Welcome back,
I got a bit late with publishing my blog today. I got busy with some work and that became the reason for this lateness.
Anyways, Today we will learn to decrypt the message. Remember we encrypted it in our recent blogs. Make sure to go through those blogs to understand this one properly.
Let us look at the program itself.
You can copy the program from below :
int main()
{
char message[100];
int i;
printf("Enter the encrypted message: ");
fgets(message, 100, stdin); // get input from user
for (i = 0; i < strlen(message); i++) {
if (message[i] >= 'a' && message[i] <= 'z') {
message[i] = 'a' + (message[i] - 'a' + 1) % 26; // shift the character by 1 position
} else if (message[i] >= 'A' && message[i] <= 'Z') {
message[i] = 'A' + (message[i] - 'A' + 1) % 26; // shift the character by 1 position
}
}
printf("The decrypted message is: %s", message);
return 0;
}
In this program, we are using a simple substitution cipher where each letter of the message is shifted by one position in the alphabet. For example, 'a' is encrypted as 'b', 'b' is encrypted as 'c', and so on. To decrypt the message, we simply shift each character back by one position in the alphabet.
To do this, we loop through each character of the message and check if it is a lowercase or uppercase letter. If it is, we shift the character back by one position using the modulo operator, which ensures that we wrap around to the beginning of the alphabet if we go past 'z' or 'Z'. Finally, we print out the decrypted message using the printf function.
Note that this is a very simple example, and there are many more sophisticated encryption methods that would require more complex decryption algorithms. However, the basic idea is the same: to reverse the encryption process and decode the message.
Let us now look at the output.
So our output is as expected. Try making your own encryption with your personal cipher and then decrypt it.
If you also want to learn basics and start your C programming journey then find a teacher today for free on Youtube.
I learnt alot from a teacher who teaches c in hindi and if you are finding someone who teaches in hindi then this person will definitely help you.
I am happy to call myself a trader and small programmer at the same time now.
Happy trading and keep learning what you love.