Question

In: Computer Science

1. Monoalphabetic substitution (using the Caesar Cipher tool right) Encipher (convert plaintext into ciphertext): meal times...

1. Monoalphabetic substitution (using the Caesar Cipher tool right) Encipher (convert plaintext into ciphertext): meal times  Decipher (convert ciphertext in to plaintext):  JR PHDQ JUHHQ 2. Polyalphabetic substitution (using the Vigenere Square in the lecture slide) Encipher: fall  Decipher:  VPX TWOKM

Solutions

Expert Solution

def encrypt(text,s):
result = ""
   # transverse the plain text
   for i in range(len(text)):
      char = text[i]
      # Encrypt uppercase characters in plain text
      
      if (char.isupper()):
         result += chr((ord(char) + s-65) % 26 + 65)
      # Encrypt lowercase characters in plain text
      else:
         result += chr((ord(char) + s - 97) % 26 + 97)
      return result
#check the above function
text = "meal times"
s = 4

print "Plain Text : " + text
print "Shift pattern : " + str(s)
print "Cipher: " + encrypt(text,s)

This is the encipher of Monoalphabetic substitution with key 4.

message = "JR PHDQ JUHHQ"
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

for key in range(len(LETTERS)):
    translated = ''
    for symbol in message:
        if symbol in LETTERS:
            num = LETTERS.find(symbol)
            num = num - key
            if num < 0:
                num = num + len(LETTERS)
            translated = translated + LETTERS[num]
        else:
            translated = translated + symbol
    print('Hacking key #%s: %s' % (key, translated))

This is the solution for deciphering monoalphabetic substitution using each and every key. By observing all the outputs the solution is "GO MEAN GREEN".

2.

For viginere cipher, we should have a key with which we have to encipher the given text. So, Giving the function for viginere cipher in python,

import random
import string
from itertools import cycle

def encrypt(flag , key):
        ciphertext=[]                           
        for i,j in zip(flag,cycle(key)):
                    x=(ord(i)+ord(j))%95
                    x+=ord(' ')
                    ciphertext.append(chr(x))
        return("" . join(ciphertext))

For deciphering, the function is as follows,

def generateKey(string, key): 
    key = list(key) 
    if len(string) == len(key): 
        return(key) 
    else: 
        for i in range(len(string) - 
                       len(key)): 
            key.append(key[i % len(key)]) 
    return("" . join(key)) 

def originalText(cipher_text, key): 
    orig_text = [] 
    for i in range(len(cipher_text)): 
        x = (ord(cipher_text[i]) - 
             ord(key[i]) + 26) % 26
        x += ord('A') 
        orig_text.append(chr(x)) 
    return("" . join(orig_text))

if __name__ == "__main__": 
    string = input()
    keyword = input()
    key = generateKey(string, keyword) 
    cipher_text = cipherText(string,key) 
    print("Ciphertext :", cipher_text) 
    print("Original/Decrypted Text :",  
           originalText(cipher_text, key)) 

Related Solutions

Cryptography: Using columnar cipher, find the plaintext and the key that generated this ciphertext: ykccjosaiawiekhriogrrlrni Keep...
Cryptography: Using columnar cipher, find the plaintext and the key that generated this ciphertext: ykccjosaiawiekhriogrrlrni Keep in mind that only letter j was used for padding. (Show your detailed work)
Using playfair cipher, decrypt the ciphertext “GKSKHALTYZ” using the keyword “UNIVERSITY”
Using playfair cipher, decrypt the ciphertext “GKSKHALTYZ” using the keyword “UNIVERSITY”
Using playfair cipher, encrypt the plaintext “SUCCESS” using the keyword “MIDTERMEXAM”
Using playfair cipher, encrypt the plaintext “SUCCESS” using the keyword “MIDTERMEXAM”
A message has been encrypted by Bob using row transposition cipher to give the following ciphertext:...
A message has been encrypted by Bob using row transposition cipher to give the following ciphertext: TTNA APTM TSUO AODW COIX KNLY PETZ However when Bob shared the key with Alice, it got copied multiple times and looks like: …. 6 7 4 3 1 2 5 6 7 4 3 1 2 5 6 7 4 3 1 2 5 6 7 4 3 1 2 5 6 7 4 3 1 2 …… You see a series of...
Programming Language C++ Encrypt a text file using Caesar Cipher. Perform the following operations: Read the...
Programming Language C++ Encrypt a text file using Caesar Cipher. Perform the following operations: Read the console input and create a file. ['$' character denotes end of content in file.] Close the file after creation. Now encrypt the text file using Caesar Cipher (Use key value as 5). Display the contents of the updated file. #include <iostream> using namespace std; int main() { // write code here }
Binary file IO Suppose a file has been encrypted using the Caesar cipher as described above,...
Binary file IO Suppose a file has been encrypted using the Caesar cipher as described above, and you know the secret key. Write a program to decrypt (or decode) the file. Your program will prompt the user to enter an input file name for the encrypted file, an output file name for the unencrypted version of the input file, and the secret key. Create a DataInputStream for the input file and a DataOutputStreams for the output file. Next, read the...
You are writing a program that encrypts or decrypts messages using a simple substitution cipher. Your...
You are writing a program that encrypts or decrypts messages using a simple substitution cipher. Your program will use two constant strings. One will represent the code for encryption: going from the original message (called the plaintext) to the encrypted version of the message. The other will be “abcdefghijklmnopqrstuvwxyz” (the lowercase alphabet. Your program will ask the user whether they want to 1) encrypt a message, 2) decrypt a message, or 3) quit. If they choose encrypt or decrypt, you...
write a C++ program that : 1. Perform a rot13 substitution 2. Perform a caesar encryption...
write a C++ program that : 1. Perform a rot13 substitution 2. Perform a caesar encryption given a dictionary 3. Perform a caesar decryption given a dictionary 4. Create a random caesar cipher dictionary If user prints: -r : Perform rot13 substitution -g : generate a random caesar cipher dictionary. -e: Encrypt using the caesar cipher -d : Decrypt using the caesar cipher The format for the caesar cipher dictionary is a file with 26 pairs of letters, one per...
Writing a caesar cipher in ARM assembly. INSTRUCTIONS: Step 1: The first thing you should do...
Writing a caesar cipher in ARM assembly. INSTRUCTIONS: Step 1: The first thing you should do is modify the case conversion program String.s (provided) Instead of subtracting 32 from all numbers you want to add a constant number which we will call the key. Assume that all input will be lowercase. So it'll look like this, k = 2; letter = 'a'; newletter = k+letter; Above is pseudocode and ABOVE NOT ASSEMBLY CODE DO NOT COPY. Use bl puts to...
These questions are about math cryptography 1) Encrypt the plaintext "this is a secret message" using...
These questions are about math cryptography 1) Encrypt the plaintext "this is a secret message" using the affine function f(x) = 5x + 7 mod 26. 2) Determine the number of divisors of 2n, where n is a positive integer.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT