#include<stdio.h> #include<stdlib.h> int mod(int x, int y) { while(x < 0) { x += y; } return x % y; } char decrypt_fun(int shift, char l) { if(l <= 'z' && l >= 'a') { return 'a' + mod((int)(l - 'a') - shift, 26); } if(l <= 'Z' && l >= 'A') { return 'A' + mod((int)(l - 'A') - shift, 26); } return l; } char encrypt_fun(int shift, char l) { if(l <= 'z' && l >= 'a') { return 'a' + mod((int)(l - 'a') + shift, 26); } if(l <= 'Z' && l >= 'A') { return 'A' + mod((int)(l - 'A') + shift, 26); } return l; } int main(void) { int key = 3; int input; do { printf("Enter the decryption key: "); scanf("%d", &input); if(input != key) { printf("Wrong key!\n"); } } while(input != key); // remove the new line in buffer while (getchar () != '\n' ); char code; FILE* inputFile = fopen("encrypted.txt", "r"); FILE* outputFile = fopen("decrypted.txt", "w"); //exit program if file doesn’t open if(inputFile==NULL || outputFile==NULL) { printf("File could not be open!!"); exit(0); } do { code = (char)fgetc(inputFile); if(code != EOF) { putc(decrypt_fun(key, code),outputFile); } } while(code != EOF); fclose(inputFile); fclose(outputFile); printf("File decrypted!\n"); printf("Do you want to re-encrypt the file(y/n): "); scanf("%c", &code); if(code == 'y') { printf("Enter an encryption key: "); scanf("%d", &key); inputFile = fopen("decrypted.txt", "r"); outputFile = fopen("encrypted.txt", "w"); //exit program if file doesn’t open if(inputFile==NULL || outputFile==NULL) { printf("File could not be open!!\n"); exit(0); } do { code = (char)fgetc(inputFile); if(code != EOF) { putc(encrypt_fun(key, code),outputFile); } } while(code != EOF); fclose(inputFile); fclose(outputFile); printf("File encrypted!\n"); } printf("Goodbye!\n"); }
Hi. please find the code.. i have given code comments so that it is very easy for you to understand the flow. In case of any doubts, please ask in comments. If the answer helps you, please upvote. Thanks!
Please answer this problem without using iostream and without strings or arrays. Just use stdio.h 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...
Assignment 7: Caesar Cipher Assignment 7 You will create a Caesar cipher which allows the user to specify the key and the text to be encrypted. A Caesar cipher is a simple substitution cipher wherein each letter in the message is shifted a certain number of spaces down the alphabet -- this number is called the key. a b c d e f g h i j k l m n o p q r s t u v w...
**DO IT AS PYTHON PLEASE** The Trifid Cipher General Problem Description The Trifid cipher (not to be confused with the creatures from the classic science-fiction film "The Day of the Triffids") is an algorithm that enciphers a plaintext message by encoding each letter as a three-digit number and then breaking up and rearranging the digits from each letter's encoded form. For this assignment, you will create a set of Python functions that can encode messages using this cipher (these functions...
Can someone please help me for this assignment? Cryptography — the science of secret writing — is an old science; the first recorded use was well before 1900 B.C. An Egyptian writer used previously unknown hieroglyphs in an inscription. We will use a simple substitution cypher called rot13 to encode and decode our secret messages. ROT13 ("rotate by 13 places", sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the 13th letter after it, in...
the w 2. This problem explores the use of a one-time pad version of t In this scheme, the key is a stream of random numbers between 0 and example, if the key is 3 19 5..., then the first letter of plaintext is encrypted with a shift of 3 letters, the second with a shift of 19 letters, the third with a shift of 5 letters, and so on. a. Encrypt the plaintext sendmoremoney with the key stream 9...
ior new tr k%2005%281 %29, You are just hired by Google as a senior software developer and your supervisor assigns you the following task: You are responsible for the development of a program that encrypts and decrypts text messages using the Caesar shift, which is one of the oldest and widely known forms of encryption Caesar shift is a type of substitution encryption method in which each letter in the text is 'shifted' a fixed mumber of positions down the...
Part 3: Transposition Ciphers #can't use ord or chr functions You must implement three transposition ciphers (the "backwards" cipher, the Rail Fence cipher, and the Column Transposition cipher) where the ciphertext is created via an altered presentation of the plaintext. The algorithm for each is detailed in the function descriptions in this section. (13 points) def backwards_cipher(plaintext, key): • Parameter(s): plaintext ----- a string; the message to be encrypted key ----- an integer; the number to control this cipher •...
C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...
#include #include #include #include #include #include #include using namespace std; const int MAX = 26; string addRandomString(int n) { char alphabet[MAX] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; string res = ""; for (int i = 0; i < n; i++) res = res + alphabet[rand() % MAX]; return res;...
Create C++ program.Convert this string to Tap Code using structures. It is very important to use structures in this program. The tap code is based on a Polybius square using a 5×5 grid of letters representing all the letters of the Latin alphabet, except for K, which is represented by C. The listener only needs to discriminate the timing of the taps to isolate letters. Each letter is communicated by tapping two numbers the first designating the row (Down) the...