Java代写:CS413 Data Security

Introduction

古典密码在密码学中,有着举足轻重的作用。做为Data security领域的基础算法理念,离不开其中的置换和置乱两大算法。
置换,即保持明文中的字符本身,但对字符的顺序进行重新排列的算法。
置乱,即将明文中的字符,用其他字符或字符序列进行替换。
而将经过加密的密文,找到其中的统计规律,并还原出其中的原文,称为密码破解。
而本次作业就是需要找到统计规律,进行密码破解。

Requirement

An encrypted file, cryptfile1.txt, is given. Your task is to decrypt it. The file was encrypted using some substitution algorithm. The easiest way to break such encryptions is by an analysis of letter frequency. You can go to the library or the Web and get information on the relative frequency of letters in the English language. A program, LetterCount.java, is also given which would allow you to find this yourself. You would simply have to choose a source text file that is sufficiently long and sufficiently representative of English that the relative frequencies of letters in it is pretty much the same as the relative frequencies given in published sources. The real value of LetterCount.java is that it provides sample code that you code adapt to decryption purposes. This encryption is simple enough that in theory you could do it by hand. If you find that your initial attempt by hand is netting nothing, you may want to write a program to help. You should hand in the results of your decryption effort.

Analysis

本题需要利用给出的Java框架,以及密文文件,写出解密算法,进行破解
下面是一段密文:

1
2
3
4
5
6
7
pmefp wunhi igsrh lxjsv xlmwg hyhig
rkfmk zsgep gsvhw hbdth swxtv shmkm
otckt euiig hgnmo ceess theoh snegs
eepws lmrsw mwgep piheg vewlx lexek
mepmr skmkw sjxlm wfvii heziv ekisr
ehcwu xlias hoofo mkveg sette adrla
xlivi lmrom fivxl lsphw ytsjv vphwq

首先自然是发现这段文字中,每个字母出现的频率是不一样的,首先猜测仅进行了置换。
任意找一个词频表,试着解析。
果然出现了apple,cable之类的可见词汇。

Tips

  1. 根据不同的词频,写程序大胆猜测
  2. 必要时需要进行分词,写程序对不同组合进行尝试
  3. 当发现可见字符时,记录所采用的算法
  4. 猜测密钥