I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text and key
My Current Code is:
void SubDecrypt(char *message, char *encryptKey) {
int iteration;
int iteration_Num_Two = 0;
int letter;
printf("Enter Encryption Key: \n");
//Display the message to enter encryption
key
scanf("%s", encryptKey);
//Input
the Encryption key
for (iteration = 0; message[iteration] != '0';
iteration++)
//loop will continue till
message reaches to end
{
letter = message[iteration];
//Assign
the first character of message to letter
if (letter >= 'A' && letter <= 'Z')
//Check the letter is between 'A' to 'Z' i.e/
upper case character or not
{
letter = letter - 32;
//Move the letter to 32 characters back
}
if (letter >= 65 && letter <= 90) {
//After subtraction if the
letter lies in the range 65 to 90(inclusive)
for (iteration_Num_Two = 0; iteration_Num_Two < 27;
iteration_Num_Two++) //loop will continue from 0 to 26
{
if (message[iteration] ==
encryptKey[iteration_Num_Two])
//Check if the message[iteration] and encryptKey[iteration_Num_Two]
will equal then terminate the loop
{
break;
}
}
message[iteration] = 'A' + iteration_Num_Two;
//Set the
message[iteration] to the value of iteration_Num_Two+'A'(uppercase)
i.e/ 65+iteration_Num_Two
}
printf("%s\n", message);
//Display the message
}
;
printf("CipherText message: %s\n", message);
//Display
the cipher text
printf("%s\n", encryptKey);
//Display
the encryptKey
}
The Output is:
PLEASE BE ADVISED IVE ONLY PROVIDED MY CODE FOR THE FUNCTION NOT MY MAIN USER CODE. COULD YOU PLEASE SHOW ME WHERE IVE GONE WRONG
You have made two or three mistakes , all these mistakes have been corrected in the below code
#include<stdio.h>
void SubDecrypt(char *message, char *encryptKey) {
int iteration;
int iteration_Num_Two = 0;
int letter;
printf("Enter Encryption Key: \n"); //Display the message to enter
encryption key
scanf("%s", encryptKey); //Input the Encryption key
for (iteration = 0; message[iteration] != '\0'; iteration++) //loop
will continue till message reaches to end
{
letter = message[iteration]; //Assign the first character of
message to letter
if (letter >= 'a' && letter <= 'z') //Check the
letter is between 'a' to 'z' i.e/ lower case character or not
{
letter = letter - 32; //Move the letter to 32 characters back for
converting into upper case letter
}
if (letter >= 65 && letter <= 90) { //After
subtraction if the letter lies in the range 65 to
90(inclusive)
for (iteration_Num_Two = 0; iteration_Num_Two < 27;
iteration_Num_Two++) //loop will continue from 0 to 26
{
if (letter == encryptKey[iteration_Num_Two]) //Check if the letter
and encryptKey[iteration_Num_Two] will equal then terminate the
loop
{
break;
}
}
if(message[iteration]>='a' &&
message[iteration]<='z') //WHEN our original message is small so
convert to equivalent small letter
message[iteration]='a'+iteration_Num_Two;
else
message[iteration] = 'A' + iteration_Num_Two; //Set the
message[iteration] to the value of iteration_Num_Two+'A'(uppercase)
i.e/ 65+iteration_Num_Two
}
printf("%s\n", message); //Display the message
}
;
printf("CipherText message: %s\n", message); //Display the cipher
text
printf("%s\n", encryptKey); //Display the encryptKey
}
int main()
{
char message[]="SCGGW";
char encryptKey[100];
SubDecrypt(message,encryptKey);
}
you can compare with your code to find your mistakes , also the key is in upper case that is why i've added the code where you need to first convert lower case to upper case ( you were doing for uppper case) .
Also in your output you have entered a wrong key which contain two consecutive W so remove that one W .
the correct output is shown below
I hope this will help you so please give positive ratings :))
I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text an...
Question: Please Provide Comments on each Line of code explaining what the C Function is doing throughout the code. // Function used for substitution encryption void SubEncrypt(char *message, char *encryptKey) { int iteration = 0; printf("Enter Aphabet Encryption Key: \n"); scanf("%s", encryptKey); for (iteration = 0; iteration < strlen(message); iteration++) { char letter = message[iteration]; if (letter >= 'A' && letter <= 'Z') { letter = encryptKey[letter - 'A']; } message[iteration] = letter; } printf("CipherText message: %s\n", message); } //_________________________________________________________________________________________________________________________________________________...
Write helpful comments for the following code: use Vigenere cipher tech to encrypt and decrypt message The code: #include<stdio.h> #include <stdlib.h> char arr[26][26]; char message[22], key[22], emessage[22], retMessage[22]; int findRow(char); int findColumn(char); int findDecRow(char, int); int main() { int i = 0, j, k, r, c; k = 96; for (i = 0; i<26; i++) { k++; for (j = 0; j<26; j++) { arr[i][j] = k++; if (k == 123) k = 97; } } printf("\nEnter message\n"); fgets(message, 22,...
C PROGRAMMING Implement a function (using only #include library) that can encrypt/decrypt with a substitution cipher. cipher_sub (a, b, c, d) a is the string that has the data that will be encrypted or decrypted b is the string that has the result of the encrypt/decrypt c is the code string used for our substitution cipher (27 entries plus '\0' character) d is an integer that will pass two constants defined as ENC (encrypt) or DEC (decrypt) --> The function...
Caesar Cipher v3 Decription Description A Caesar cipher is one of the first and most simple encryption methods. It works by shifting all letters in the original message (plaintext) by a certain fixed amount (the amounts represents the encryption key). The resulting encoded text is called ciphertext. Example Key (Shift): 3 Plaintext: Abc Ciphertext: Def Task Your goal is to implement a Caesar cipher program that receives the key and an encrypted paragraph (with uppercase and lowercase letters, punctuations, and...
Write the programming C please, not C++. The main function should be to find the offset value of the ciper text "wPL2KLK9PWWZ7K3ST24KZYKfPMKJ4SKLYOKRP4KFKP842LK0ZTY43 " and decrypt it. In cryptography, a Caesar Cipher is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be...
. Please write a function that will do the following Decryption of a message encrypted with a substitution cipher given cipher text only without any key Please provide comments on each line of code outlining what that line is doing. Note: Only the Function is to be written, all user inputs i.e the text to be decrypted will be entered earlier in the program. Code must be written in C and be able to be compiled using GCC If any...
C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...
C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...
Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util.*; import java.lang.*; /** * * @author STEP */ public class ShiftCipher { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner(System.in); String plainText; System.out.print("Please enter your string: "); // get message plainText = input.nextLine(); System.out.print("Please enter your shift cipher key: "); // get s int s = input.nextInt(); int...
C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string using the RSA algorithm (C90 language only). It can contain ONLY the following libraries: stdio, stdlib, math and string. I want to use the following function prototypes to try and implement things: /*Check whether a given number is prime or not*/ int checkPrime(int n) /*to find gcd*/ int gcd(int a, int h) void Encrypt(); void Decrypt(); int getPublicKeys(); int getPrivateKeys();...