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
}