Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

use the text and code : 

 

cipher.txt

xun gmr jznqymxu qzhhxzupmur ytmq dnvhq vavpncd vlvhpq mq txl xh mb ytn

anhncxud lmii vpphnqq cnyxx nqenamviid vbynh ytn rxipnu rixgnq ltmat gnavcn

v ozgmivuy axcmurxzy evhyd bxh ymcnq ze ytn cxfncnuy qenvhtnvpnp gd 

exlnhbzi txiidlxxp lxcnu ltx tnienp hvmqn cmiimxuq xb pxiivhq yx bmrty qnkzvi

tvhvqqcnuy vhxzup ytn axzuyhd

 

 

python code :

#!/usr/bin/env python3

from collections import Counter

import re

TOP_K  = 20

N_GRAM = 3

# Generate all the n-grams for value n

def ngrams(n, text):

    for i in range(len(text) -n + 1):

        # Ignore n-grams containing white space

        if not re.search(r'\s', text[i:i+n]):

           yield text[i:i+n]

# Read the data from the ciphertext

with open('ciphertext.txt') as f:

    text = f.read()

# Count, sort, and print out the n-grams

for N in range(N_GRAM):

   print("-------------------------------------")

   print("{}-gram (top {}):".format(N+1, TOP_K))

   counts = Counter(ngrams(N+1, text))        # Count

   sorted_counts = counts.most_common(TOP_K)  # Sort 

   for ngram, count in sorted_counts:                  

       print("{}: {}".format(ngram, count))   # Print

1. use the frequency analysis to figure out the encryption key and the original
plaintext.
using the python code provided and the cipher
Using the frequency analysis, you can find out the plaintext.
It is better to use capital letters for plaintext, so for the same letter, to know
which is plaintext and which is ciphertext. use the tr command to do this.
For example, letters m, t, and y in in.txt with letters B, P, S, respectively; the results
are saved in out.txt.
$ tr 'mty' 'BPS' <in.txt > out.txt
cipher.txt
xun gmr jznaymxu gzhhxzupmur ytmq dnvhq vavpncd vlvhpq mq txl xh mbytn
anhncxud Imii vpphngg cnyxx ngenamviid vbynh ytn rxipnu rixgnq ltmat gnavcn
v ozgmivuy axcmurxzy evhyd bxh ymcng ze ytn cxfncnuy genvhtnvpnp gd
exlnhbzi txiidlxxp Ixcnu Itx tnienp hvman cmiimxuq xb pxiivhg yx bmrty gnkzvi
tvhvqgcnuy vhxzup ytn axzuyhd
python code:
#!/usr/bin/env python3
from collections import Counter
import re
TOP_K = 20
N_GRAM = 3
# Generate all the n-grams for value n
def ngrams (n, text):
for i in range (len(text) -n + 1):
# Ignore n-grams containing white space
if not re.search(r'\s', text[i:i+n]):
yield text[i:i+n]
# Read the data from the ciphertext
with open('ciphertext.txt') as f:
text = f.read()
# Count, sort, and print out the n-grams
for N in range(N_GRAM):
print("--
--")
print("{}-gram (top {}):".format(N+1, TOP_K))
counts = Counter (ngrams(N+1, text))
sorted_counts = counts.most_common(TOP_K) # Sort
for ngram, count in sorted_counts:
print("{}: {}".format(ngram, count)) # Print
# Count
expand button
Transcribed Image Text:1. use the frequency analysis to figure out the encryption key and the original plaintext. using the python code provided and the cipher Using the frequency analysis, you can find out the plaintext. It is better to use capital letters for plaintext, so for the same letter, to know which is plaintext and which is ciphertext. use the tr command to do this. For example, letters m, t, and y in in.txt with letters B, P, S, respectively; the results are saved in out.txt. $ tr 'mty' 'BPS' <in.txt > out.txt cipher.txt xun gmr jznaymxu gzhhxzupmur ytmq dnvhq vavpncd vlvhpq mq txl xh mbytn anhncxud Imii vpphngg cnyxx ngenamviid vbynh ytn rxipnu rixgnq ltmat gnavcn v ozgmivuy axcmurxzy evhyd bxh ymcng ze ytn cxfncnuy genvhtnvpnp gd exlnhbzi txiidlxxp Ixcnu Itx tnienp hvman cmiimxuq xb pxiivhg yx bmrty gnkzvi tvhvqgcnuy vhxzup ytn axzuyhd python code: #!/usr/bin/env python3 from collections import Counter import re TOP_K = 20 N_GRAM = 3 # Generate all the n-grams for value n def ngrams (n, text): for i in range (len(text) -n + 1): # Ignore n-grams containing white space if not re.search(r'\s', text[i:i+n]): yield text[i:i+n] # Read the data from the ciphertext with open('ciphertext.txt') as f: text = f.read() # Count, sort, and print out the n-grams for N in range(N_GRAM): print("-- --") print("{}-gram (top {}):".format(N+1, TOP_K)) counts = Counter (ngrams(N+1, text)) sorted_counts = counts.most_common(TOP_K) # Sort for ngram, count in sorted_counts: print("{}: {}".format(ngram, count)) # Print # Count
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education