Question

Some cryptography and a little computer security. You find an odd DeLorean parked around the corner....

Some cryptography and a little computer security.

You find an odd DeLorean parked around the corner. Realizing that Doc Brown has left the

keys in the ignition, you decide that a quick trip back to Rome in 40 BC is in order. A few mint

condition coins, and possibly a picture of Vincengetorix will be highly remunerative.

As usual, the car fails and you are stranded.

All is not lost, Julius Caesar recruits you for his secret service as a cryptographer. Falerian

wine is palatable, you have acquired a taste for garum (don't ask), and there are more than

enough other attractions to make your life comfortable.

Fortunately, you have your laptop, running linux with a python interpreter, and by the use of

lemon juice, copper denarii and silver sestarii you are able to rig up a battery to keep it running.

1. Write a program that takes a key (a number from 1 to 26) an input le name, and an

output le name from the command line and uses the key to encrypt it with a Caesar

cipher. A Caesar cipher performs modular addition of the key and the letter. If the key is

1 then a->b, b->c, ..., y->z, z->

a . Ignore all the things that aren't the letters from a to z

(simply pass them through) and you will want to put the letters into lower case. Use the

le message1.txt and a key of 7 to encrypt it. (You can do this one pretty easily in bash

too.)

2. Cato and Junius Brutus are using the cipher to encrypt their communications. In Latin as

well as that vulgar Germanic language Englisc the letter 'e' is the most common letter. 't'

is the second most common. Write a program to count the numbers of each letter in the

message. (i.e. how common is each symbol) Then use that to find the key for the message.

Use the le ceaser1.txt for input.

3. Caesar ciphers form a group. Therefore repeated encryption with any key will recover the

message. Use the results from your answer to the second question to nd the message.

The proper decryption will be when 'e' is the most common letter and 't' is the second

most common. Use the le ceaser2.txt for input

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import sys

def countChar(data, ch):
string = ''
for line in data:
string += line
count = 0
for c in string:
if c == ch:
count += 1
return count

def countChars(data):
for i in range(0, 26):
count = countChar(data, chr(ord('a') + i))
print('count of ' + chr(ord('a') + i) + ' is ' + str(count))

def Main():
key = sys.argv[1]
inputFile = sys.argv[2]
outputFile = sys.argv[3]
with open(inputFile, 'r') as f:
data = f.readlines()
data = [x.strip('\n') for x in data]
countChars(data)
out = open(outputFile, 'w')
outputData = []
for line in data:
outline = ''
for ch in line:
if ch.isupper():
ch = ch.lower()
if ch.isalpha():
ch = chr(ord('a') + (ord(ch) - ord('a') + key) % 26)
outline = outline + ch
outline = outline + '\n'
outputData.append(outline)
out.writelines(outputData)
out.close()

Main()


-----------------------------------------------------------------------------------------------------
SAMPLE OUTPUT:

Input.txt :
'Who will watch the watchmen.' Juvenal
'Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin.' John Von Neumann
'The price of freedom is eternal vigilance.' Thomas Jefferson
'And so it often happens that an apparently ingenious idea is in fact a weakness which the scientific cryptographer seizes on for his solution.' Herbert Yardley


Output.txt:
'dov dpss dhajo aol dhajotlu.' qbcluhs
'hufvul dov jvuzpklyz hypaotlapjhs tlaovkz vm wyvkbjpun yhukvt kpnpaz pz, vm jvbyzl, pu h zahal vm zpu.' qvou cvu ulbthuu
'aol wypjl vm myllkvt pz lalyuhs cpnpshujl.' aovthz qlmmlyzvu
'huk zv pa vmalu ohwwluz aoha hu hwwhyluasf punlupvbz pklh pz pu mhja h dlhrulzz dopjo aol zjpluapmpj jyfwavnyhwoly zlpglz vu mvy opz zvsbapvu.' olyilya fhykslf

Add a comment
Know the answer?
Add Answer to:
Some cryptography and a little computer security. You find an odd DeLorean parked around the corner....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Cryptography, the study of secret writing, has been around for a very long time, from simplistic...

    Cryptography, the study of secret writing, has been around for a very long time, from simplistic techniques to sophisticated mathematical techniques. No matter what the form however, there are some underlying things that must be done – encrypt the message and decrypt the encoded message. One of the earliest and simplest methods ever used to encrypt and decrypt messages is called the Caesar cipher method, used by Julius Caesar during the Gallic war. According to this method, letters of the...

  • Computer Security Question about the Caesar Cipher: I also don't know this part of the problem...

    Computer Security Question about the Caesar Cipher: I also don't know this part of the problem Hello I am not sure how to figure this out Hello so for question 3, I think its +23 "the password is qqzzqqz" choose the correct multiple choice Question1 2 pts The following cipher text was produced by the Caesar Cipher: The Caesar cipher cryptanalysis technique from lecture calculates the most likely keys. When the technique is applied in this case, which of the...

  • Assignment 7: Caesar Cipher Assignment 7 You will create a Caesar cipher which allows the user...

    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...

  • 1) Echo the input: First, you should make sure you can write a program and have...

    1) Echo the input: First, you should make sure you can write a program and have it compile and run, take input and give output. So to start you should just echo the input. This means you should prompt the user for the plaintext, read it in and then print it back out, with a message such as "this is the plaintext you entered:". [4 points, for writing a working program, echoing the input and submitting the program on the...

  • This assignment tests your ability to write C programs that handle keyboard input, formatted console output,...

    This assignment tests your ability to write C programs that handle keyboard input, formatted console output, and input/output with text files. The program also requires that you use ctype functions to deal with the logic. In this program, you will input from the user two characters, which should both be letters where the second letter > the first letter. You will then input a file character-by-character and output those letters that fall between the two characters (inclusively) to an output...

  • Can someone please help me for this assignment? Cryptography — the science of secret writing —...

    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...

  • JAVA Problem: With the recent news about data breaches and different organizations having their clients’ information...

    JAVA Problem: With the recent news about data breaches and different organizations having their clients’ information being exposed, it is becoming more and more important to find ways to protect our sensitive data. In this program we will develop a simple tool that helps users generate strong passwords, encrypt and decrypt data using some cyphering techniques. You will need to create two classes. The first class is your driver for the application and contains the main method. Name this class...

  • JAVA PROJECT Part 1 - Normalize Text The first thing we will do is normalize the...

    JAVA PROJECT Part 1 - Normalize Text The first thing we will do is normalize the input message so that it’s easier to work with. Write a method called normalizeText which does the following: Removes all the spaces from your text Remove any punctuation (. , : ; ’ ” ! ? ( ) ) Turn all lower-case letters into upper-case letters Return the result. The call normalizeText(“This is some \“really\” great. (Text)!?”) should return “THISISSOMEREALLYGREATTEXT” Part 2 - Obfuscation...

  • Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D....

    Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D. Decryption Implement two decryption functions corresponding to the above ciphers. When decrypting ciphertext, ensure that the produced decrypted string is equal to the original plaintext: decryptCaesar(ciphertext, rshift) == plaintext decryptVigenere(ciphertext, keyword) == plaintext Write a program decryption.cpp that uses the above functions to demonstrate encryption and decryption for both ciphers. It should first ask the user to input plaintext, then ask for a right...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT