I am a C student and we got a task to get an input of integers, reverse it and encrypt the integers into characters like integer 0 = A, 1 = B and so on. For example, encrypting 1546 into GEFB. It’s our first semester and we have not learnt anything about strings or encryption at all. I got the reverse part down but encryption is making it difficult. If anyone can give some tips and explanation, it would be much appreciated. More examples, 1546 GEFB 7777 HHHH 5555 FFFF 1234 EDCB

Share

The easiest way to approach this would be to create an array of characters, where each character corresponds to a number. So, for example, you could have an array like this:

Then, to encrypt a number, you would just need to look up the corresponding character in the array. So, for example, to encrypt the number 1546, you would look up the characters ‘G’, ‘E’, ‘F’, and ‘B’ in the array, which would give you the encrypted string “GEFB”.

To decrypt a string, you would just need to do the reverse – look up the numbers that correspond to each character in the string. So, for example, to decrypt the string “GEFB”, you would look up the numbers ‘G’, ‘E’, ‘F’, and ‘B’

If you’re not allowed to use strings, then you’ll just have to use numbers. So, for example, you could have an array of numbers, where each number corresponds to a character. So, for example, you could have an array like this:

int numbers[26] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25}; Then, to encrypt a character, you would just need to look up the corresponding number in the array. So, for example, to encrypt the character ‘G’, you would look up the number 6 in the array, which would give you the encrypted number 6.

To decrypt a number, you would just need to do the reverse – look up the character that corresponds to the number. So, for example, to decrypt the number 6, you would look up the character ‘G’ in the array.