Thread: Encripting Using ASCII

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    8

    Stack Structure -Help me outttttt

    Hello there, yet again, my noobness.


    Ok, so I need to encrypt a file using this delimitations:

    -You will be given a file with a character, which is your key.(in this hypothetical situation lets use 'a')

    -You will encrypt a string by each character. for instance

    "Hello"

    h=104
    e=101
    l=108
    l=108
    o=111

    -add the value of your character with your key and then multiply it by 2.
    For the sake of not doing this as big as it will be,
    Lets do a test with h

    h=104 + a=97
    104+97=201 * 2 = 402(which doesn't exist..)

    AS there are only 127 characters, how can I limit this to be in range of the 127.

    ***Consider that I need to take the characters which are the encryption and turn them back to normal using the same value. (in this case 'a')
    btw all this has to be done with only stdlib.h stdio.h(no fancy libraries or commands)

    I need desperate help.

    Ill virtually take a knee and kiss your feet if you help me out.

    (>'')> kirby hug!

    Thank you for being supportive to your fellow humans.

    ///////////////
    TOTAL EDIT I've managed to do the encryption and come back from it but now Im having a problem with staking structures...

    Heres the code, For some reason when I try to print the information y the nodes it doesnt go forward. from "hola" it just prints "a" when it should print "aloh"
    Whats wrong?

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    typedef struct datos{
      char letra;
      struct datos *sig;
    }LISTA;
    
    int main(int argc, char **argv)
    {
      LISTA *inicio, *nodo;
      inicio=NULL;
     char caracter;///caracter leido desde archivo, es archivo a modificar.
      char llave;///caracter leido desde el archivo llave
      int variable;
      int contador=0;
      FILE *lectura;///archivo a leer(encriptar)
      FILE *escritura;///archivo donde se encriptara
      FILE *llavetura;///archivo llave
     
      if((lectura=fopen(argv[1],"r"))==NULL)//abrimos archivos
        {
          printf("no se puede abrir lectura\n");
        }
      else
        {
          printf("si se pudo abrir lectura\n");
        }
      if(( escritura=fopen(argv[2],"w"))==NULL)
        {
          printf("No se pudo escritura\n");
        }
      else
        {
          printf("si se pudo escritura\n");
        }
      if(( llavetura=fopen(argv[3],"r"))==NULL)
        {
          printf("No se pudo llavetura\n");
        }
      else
        {
          printf("si se pudo llavetura\n");
        }    ////acabamos de abrir archivos
      llave=getc(llavetura);
    
    
      nodo=malloc(sizeof(LISTA));//Create Space
      if(nodo==NULL)
        {
          printf("No hay memoria");
          exit(1);
        }//if
      inicio=NULL;
     while((caracter=getc(lectura))!=EOF)//save on the space each character...but I dont think this is working, could you help me out?
        {
          contador++;
          nodo->letra=caracter;
          if(inicio=NULL)
        {  
          inicio=nodo;
          nodo->sig=NULL;
        }
          else
        {
    printf("Estamos entrando por %d con la variable %c\n",contador,nodo->letra);
          nodo->sig=inicio;
          inicio=nodo;
        }//guardamos en cada espacio cada caracter.
        }
          nodo=inicio;
          while(nodo!=NULL)///prints
        {
          printf("%c \n", nodo->letra);
          nodo=nodo->sig;
        }//while
    }
    Last edited by XIIIX; 09-19-2011 at 06:45 PM. Reason: Something got solved.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ASCII character with ASCII value 0 and 32
    By hitesh_best in forum C Programming
    Replies: 4
    Last Post: 07-24-2007, 09:45 AM
  2. ascii rpg help
    By aaron11193 in forum C Programming
    Replies: 18
    Last Post: 10-29-2006, 01:45 AM
  3. encripting a string
    By j_spinto in forum C Programming
    Replies: 8
    Last Post: 07-28-2005, 08:47 AM
  4. "encripting" by using ^
    By Trauts in forum C++ Programming
    Replies: 10
    Last Post: 11-10-2004, 07:50 PM
  5. encripting 4-digit integer?
    By o0o in forum C++ Programming
    Replies: 5
    Last Post: 12-25-2003, 09:48 PM

Tags for this Thread