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

I need help writing a simple encryption scheme in ruby using a Substitution Ciph

ID: 3562061 • Letter: I

Question

I need help writing a simple encryption scheme in ruby using a Substitution Cipher. Each letter of the alphabet is assigned another... I need to do this using two parallel strings... just leave non-alphabetic characters alone so numbers, spaces, punctuation, etc. are not changed. I also need one function, encodeCharacter, that takes a string of length 1 (ch) and a cipher string and returns the character in the cipher string that corresponds to the ch according to the substitution cipher. I also need to do a little ASCII math to determine the cipher string index that the plaintext character corresponds to.. I attempted to do this but do not know if it is correct... I will put what I have so far below....I also need an encodeString( s, cipher) that takes string s and string cipher representing the substitution. It returns a new string that is s encoded according to the provided substitution cipher.

*encodeCharacter should be inside of encodeString, basically just a loop and some concatentation, passing rest of work onto encodeCharacter

Last I need to write decodeCharacter(ch, cipher) and decodeString(s, cipher) which will be similar to encodeCharacter()... the only difference will be the indexing ( as I said before the encode needs to have ASCII math)

* this is pretty basic stuff I just need it right away and do not have time, so if you could please help that would be great! (in a very timely manner) :)

Explanation / Answer

#include void encrypt(int shift); int main(void) { int shift; int decOrEnc; printf("Amount of shifts: "); scanf("%d", &shift); printf("Type 1 to encrypt or 0 to decrypt: "); scanf("%d", &decOrEnc); while(getchar() != ' '); if (decOrEnc == 1) encrypt(shift); else { shift = -1 * shift; encrypt(shift); } return 0; } void encrypt(int shift) { char ch; printf("Please enter a string: "); ch = getchar(); while(ch != ' ') { if (ch == ' ') putchar(ch); else { if(shift == 1) putchar(ch + shift); else putchar(ch - shift); } ch = getchar(); } putchar(ch); }