Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Notebook 2: ROT ROT is a very simple cipher that is used to information hiding (

ID: 3881053 • Letter: N

Question

Notebook 2: ROT

ROT is a very simple cipher that is used to information hiding (https://en.wikipedia.org/wiki/ROT13) . Read the wiki page to understand how the encoder works.

a. Create an “encode_rot()” function to encode any given strings using ROT algorithm. The input should contain a key and a string of text. The key can be any integers both negative and positive (-12: turn left 12 positions, 36: turn right 36 positions). Only alphabet letters are encoded. The following two lines of your code will generate an output of “Ocejkpg ECP ngctp 2 !!!“. clear_text=” Machine CAN learn 2 !!!” encode_rot(clear_text, 28)

b. Create a decode_rot() to decode a ciphertext. The input only contains the ciphertext. The output contains the cleartext and the key that was used to encode text. The key will be between 0 and 25. (hint: Compare your decoded clear text with a dictionary text file and decide which one has the most dictionary words.) The following two lines will generate an output of The clear text is : “Data is like people, interrogate it hard enough and it will tell you whatever you want to hear.” The key is 16 cipher_text= “Tqjq yi byau fuefbu, ydjuhhewqju yj xqht udekwx qdt yj mybb jubb oek mxqjuluh oek mqdj je xuqh.” decode_rot(cipher_text)

c. Use your function to test more ciphertexts and show the results in your notebook . (you can use www.rot13.com or your encode_rot() function generate cipher texts).

Explanation / Answer

a)

void encode_rot(char s[100],int n)
{
//printf("1");
int i;
//char c[100];
for(i=0;s[i]!='';i++)
{
if(s[i]>=65&&s[i]<=90)
{
c[i]=(s[i]+n-65)%26+65;//for uppercase letters
}
else if(s[i]>=97&&s[i]<=122)
{
c[i]=(s[i]+n-97)%26+97;//for lowercase letters
}
else
{
c[i]=s[i]; //for non alphabetic
}

}
printf("%s",c);
}

b)For decoding based on the frequency find the key value manually then use this function

void decode_rot(char s[100],int n)
{
//printf("1");
int i;
//char c[100];
for(i=0;s[i]!='';i++)
{
if(s[i]>=65&&s[i]<=90)
{
c[i]=(s[i]-n%26-65)%26+65;//for uppercase letters
}
else if(s[i]>=97&&s[i]<=122)
{
c[i]=(s[i]-n%26-97)%26+97;//for lowercase letters
}
else
{
c[i]=s[i];
}

}
printf("%s",c);
}

c)clear_text=This is an example 1

key =1

encoded=Uijt jt bo fybnqmf 1

clear_text=You can do this!!!

key = 13

encoded=Lbh pna qb guvf!!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote