I am working on a problem and I am a bit stuck so I thought to ask for your help. I want to make a program with the following capabilities. The user will give a 4 digit cipher key and a text.
Then the text will be converted in cipher using the following method. Let's say that the text input was 'ABC' and the key was 123. Then, using the ASCII table the 'ABC' will be converted to 'BDF'. The text will be moved K positions forward in the ASCII table, where K is the corresponding digit of the key. Consider the text infinite. My first action was to convert the key to an array.
//scanning the cypher key
scanf("%d", &cypherkey);
//converting the cypher key into an array using a practical mathematic method for extracting its digit
int keyarray[4];
keyarray[0]= cypherkey/1000;
keyarray[1]= (cypherkey-keyarray[0]*1000)/100;
keyarray[2]= ((cypherkey-keyarray[0]*1000)- keyarray[1]*100)/10;
keyarray[3]= ((cypherkey-keyarray[0]*1000)- keyarray[1]*100)-keyarray[2]*10;
So, now I have the key in an array. However, I can't find a good way to read the text and then cipher it. I can't use an array because we don't know the length of the text.
I would appreciate any help!