In C language Write a program that will crack a Caesar cyphe
In C language!!!
Write a program that will crack a Caesar cypher using a brute-force approach (with some human help). You know that it is a simple Caesar cypher, but you do not know the key. So your program will need to try every key value. Starting with a key value of 1, increment each letter in the input string by this 1 (A\'s become B\'s, B\'s become C\'s, and so on) and print the resulting string. Then repeat 25 times, generating every possible output string. Then find a convenient human with a highlighter pen who can read the output and determine the key. Be carefull of rollover past the character \'z\'. If this happens you will need to subtract back to the start of the alphabet.
I suggest you use a small input string untill you get it working correctly.
For example: char input[] = \"epfexvsww\"; // albatross, key = 22
char input[] = \"jzfnlyetxlrtypdzxlyjxzyvpjdtyespoltwjxltwlwwzqespxnzxtyrlyzyjxzfdwjdzespjwplgpyzecltwtypgpceszfrseto slgplyloxtcpcqczxzgpcdpldmfedzxpzyptddpyotyrxpdeletzylcjqtwwpohtesnstxalykppddzxpnstxadtydhtxdfteddzx pnstxadlcpdhtyrtyrqczxlgtypdzxpnstxadtyulnvmzzeddzxpnstxadeslehtdsespjnzfwompxtypdelcdvjlyosfensnstxa dlnstxahszddteetyrzyespnlylaltczqofensnstxadhszdpyoesptcwzgpqczxlxdepcolxlyzespcazdenlcohtesnstxalykp pdlyopgpcjzyptdloocpddpoezxp\";
Sample Output (epfexvsww = albatross, key = 22):
0 epfexvsww
1 fqgfywtxx
2 grhgzxuyy
3 hsihayvzz
4 itjibzwaa
5 jukjcaxbb
6 kvlkdbycc
7 lwmleczdd
8 mxnmfdaee
9 nyongebff
10 ozpohfcgg
11 paqpigdhh
12 qbrqjheii
13 rcsrkifjj
14 sdtsljgkk
15 teutmkhll
16 ufvunlimm
17 vgwvomjnn
18 whxwpnkoo
19 xiyxqolpp
20 yjzyrpmqq
21 zkazsqnrr
22 albatross
23 bmcbusptt
24 cndcvtquu
25 doedwurvv
Press any key to continue . . .
Solution
Algorithm for caesar cipher:-
If Ci is the character value in the text then, Encrypted text = char(Ci + Key)%26.
WORKING C PROGRAM :-
#include<stdio.h>
void print(char s[], int key) {
char temp;
printf(\"%d :\", key);
for(int i=0; s[i]!=0; i++) {
int c_val = (s[i]-\'a\');
temp = (char)((c_val+key)%26 + \'a\');
printf(\"%c\", temp);
}
printf(\"\ \");
}
void crackCaesar(char s[])
{
for(int i=0; i<26; i++)
{
print(s, i);
}
}
int main()
{
char inp[500]; //I am asuming that maximum length of input is 500. You can change it.
printf(\"Enter the string :\ \");
scanf(\"%s\", inp);
crackCaesar(inp);
return 0;
}

