学习课程:斯坦福大学密码学公开课
课件和作业(附答案)链接:https://pan.baidu.com/s/1vogTE2Flpzi9DmoclLPGQw
提取码:1mrp

Week 1 Homework

  • Week 1 - Problem Set
    • Q1
    • Q2
    • Q3
    • Q4
    • Q5
    • Q6
    • Q7
    • Q8
    • Q9
    • Q10
  • Week 1 - Programming Assignment

Week 1 - Problem Set

Q1

先压缩再加密。
1、密文要随机性好,如果后加密的话,会导致随机性不好。同时也会泄漏压缩算法的信息。
2、压缩后数据量变小,此时加密的话会比较快。

Q2

D、把两个相同的序列连接起来作为一个新序列,这样新的序列就是可预测的了,不安全。

Q3

因为新的序列是通过AND运算得到的,那么检查最后一位时,最后一位是0的概率是0.75。
0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1
因此优势是0.25。

Q4

读懂题意就行了。

Q5

1、明文和密码的长度相同。
2、给定明文和对应的明文,能解出唯一的密钥。

Q6

选的时候不要只考虑随机性好坏,如果只考虑随机性,很有可能会错选最后一个选项。。。

Q7

计算就行。

Q8

主要是理解题意。选的节点向下不能出现坏节点。

Q9

即树的高度。当一个叶节点坏掉时,从根节点往树节点方向,每一层都需要做一个二选一选择,树的高度是多少,就要进行多少次选择。

Q10

前两题做对了这题必不会做错。

Week 1 - Programming Assignment

首先把target ciphertext和每个ciphertext异或。

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;public class Main {//给定的10个ciphertext以及target ciphertextprivate final static String string_cipher_text01 = "315c4eeaa8b5f8aaf9174145bf43e1784b8fa00dc71d885a804e5ee9fa40b1" +"6349c146fb778cdf2d3aff021dfff5b403b510d0d0455468aeb98622b137dae857553ccd8883a7bc37520e06e515d22c954eba50";private final static String string_cipher_text02 = "234c02ecbbfbafa3ed18510abd11fa724fcda2018a1a8342cf064bbde548b12b07df" +"44ba7191d9606ef4081ffde5ad46a5069d9f7f543bedb9c861bf29c7e205132eda9382b0bc2c5c4b45f919cf3a9f1cb741"; private final static String string_cipher_text03 = "32510ba9a7b2bba9b8005d43a304b5714cc0bb0c8a34884dd91304b8ad40b62b07df" +"44ba6e9d8a2368e51d04e0e7b207b70b9b8261112bacb6c866a232dfe257527dc29398f5f3251a0d47e503c66e935de812";private final static String string_cipher_text04 = "32510ba9aab2a8a4fd06414fb517b5605cc0aa0dc91a8908c2064ba8ad5ea06a0290" +"56f47a8ad3306ef5021eafe1ac01a81197847a5c68a1b78769a37bc8f4575432c198ccb4ef63590256e305cd3a9544ee41";private final static String string_cipher_text05 = "3f561ba9adb4b6ebec54424ba317b564418fac0dd35f8c08d31a1fe9e24fe56808c2" +"13f17c81d9607cee021dafe1e001b21ade877a5e68bea88d61b93ac5ee0d562e8e9582f5ef375f0a4ae20ed86e935de812";private final static String string_cipher_text06 = "32510bfbacfbb9befd54415da243e1695ecabd58c519cd4bd2061bbde24eb76a19d8" +"4aba34d8de287be84d07e7e9a30ee714979c7e1123a8bd9822a33ecaf512472e8e8f8db3f9635c1949e640c621854eba0d";private final static String string_cipher_text07 = "32510bfbacfbb9befd54415da243e1695ecabd58c519cd4bd90f1fa6ea5ba47b01c9" +"09ba7696cf606ef40c04afe1ac0aa8148dd066592ded9f8774b529c7ea125d298e8883f5e9305f4b44f915cb2bd05af513";private final static String string_cipher_text08 = "315c4eeaa8b5f8bffd11155ea506b56041c6a00c8a08854dd21a4bbde54ce56801d9" +"43ba708b8a3574f40c00fff9e00fa1439fd0654327a3bfc860b92f89ee04132ecb9298f5fd2d5e4b45e40ecc3b9d59e941"; private final static String string_cipher_text09 = "271946f9bbb2aeadec111841a81abc300ecaa01bd8069d5cc91005e9fe4aad6e04d5" +"13e96d99de2569bc5e50eeeca709b50a8a987f4264edb6896fb537d0a716132ddc938fb0f836480e06ed0fcd6e9759f404";private final static String string_cipher_text10 = "466d06ece998b7a2fb1d464fed2ced7641ddaa3cc31c9941cf110abbf409ed395980" +"05b3399ccfafb61d0315fca0a314be138a9f32503bedac8067f03adbf3575c3b8edc9ba7f537530541ab0f9f3cd04ff50d";private final static String target_text          = "32510ba9babebbbefd001547a810e67149caee11d945cd7fc81a05e9f85aac650e90" +"52ba6a8cd8257bf14d13e6f0a803b54fde9e77472dbff89d71b57bddef121336cb85ccb8f3315f4b52e301d16e9f52f904";public static void main(String[] args) throws UnsupportedEncodingException {//将每一个ciphertext转换成为BigIntegerBigInteger[] bigIntegerText = {new BigInteger(string_cipher_text01,16),new BigInteger(string_cipher_text02,16),new BigInteger(string_cipher_text03,16),new BigInteger(string_cipher_text04,16),new BigInteger(string_cipher_text05,16),new BigInteger(string_cipher_text06,16),new BigInteger(string_cipher_text07,16),new BigInteger(string_cipher_text08,16),new BigInteger(string_cipher_text09,16),new BigInteger(string_cipher_text10,16)};BigInteger bigIntgerTargetText = new BigInteger(target_text,16);//将targettext与每个ciphertext异或BigInteger[] bigIntegerXOR = {bigIntgerTargetText.xor(bigIntegerText[0]),bigIntgerTargetText.xor(bigIntegerText[1]),bigIntgerTargetText.xor(bigIntegerText[2]),bigIntgerTargetText.xor(bigIntegerText[3]),bigIntgerTargetText.xor(bigIntegerText[4]),bigIntgerTargetText.xor(bigIntegerText[5]),bigIntgerTargetText.xor(bigIntegerText[6]),bigIntgerTargetText.xor(bigIntegerText[7]),bigIntgerTargetText.xor(bigIntegerText[8]),bigIntgerTargetText.xor(bigIntegerText[9])};//思路是每个字符逐个计算for(int i=0;i<10;i++) {String XORString=bigIntegerXOR[i].toString(16);for(int j=0;j+2<=XORString.length();j=j+2) {int tmp=Integer.parseInt(XORString.subSequence(j, j+2).toString(), 16);//只输出可显示字符,不然输出会很乱if(tmp>31&&tmp<127) {System.out.print((char)tmp);}else {System.out.print("?");}}System.out.println();}}
}

把输出的结果排一下版,对齐后进行猜测。猜测思路主要来自于题目中的提示:

Hint: XOR the ciphertexts together, and consider what happens when a space is XORed with a character in [a-zA-Z].

总结一下就是:
空格异或小写字母=对应的大写字母;
空格异或大写字母=对应的小写字母。
如果该列字符多,很可能target ciphertext此处是空格。
如果该列问号多,那么优先选取该列中的大写字母,因为英文文本中间大多是小写字母。
于是有:

 0?T1 ?1@Au@!u0p?$T????RT?E??!??du?D???p??????Q??????!4Q???0D?ptT`?`????`?U@a@4 ??5
???E?E????DM??????L?S_N=??NT???N?O?????E??E????E?IC????RAU??R???????N?O???????T?NNE????E?H???S???U?SqE2???QU??N?O????R???P??????DE??V??NU??I??EAK??TM??EF???????????????T???S???D??_Dw??NAU??????N??????O?I????^I???E?O??????EG??????R?I????T???E?q??p??Q?Ep??u1P?T!????q?????T??e$??`??Pq?????? uP????P?????????Q?Q????`??????????R?E???TT??S????SI?\?4???T?????H??^T??????????R[I??V??E?S?E???T?E?A??R?R??A?O??C?R?E???TT??S????SI?\?4???O?????Y[????E??A?I????[SN???Rg???R???N?E?OM????????EO???0?T1 ?0??????e1?????4??!???A?d???????u!??T?1????@??? @??uQ??E@?`???uD?????pp??P ??
?HMP??????????ZAG?N??CP#?????????EAS?????M?C?????ET???IRN???L?H?????C????ET????????
t<?ES&????S?E<????D-?YT>???R?SA\W?W?S?????N??P???\T?E??RT??EA??EO?EYW????N?H?NRO???
th? se??et mes?ag? is? ???n us?n? a strepm cipher? never uqe ehe ?e? more than once
the secret message is? when using a stream cipher? never use the key more than once
The secret message is: when using a stream cipher, never use the key more than once

因此密文是:

The secret message is: when using a stream cipher, never use the key more than once

密文异或明文得出key为:

66396e89c9dbd8cc9874352acd6395102eafce78aa7fed28a07f6bc98d29c50b69b0339a19f8aa401a9c6d708f80c066c763fef0123148cdd8e802d05ba98777335daefcecd59c433a6b268b60bf4eF03C9A61

可以用该key解密其他的密文来验证。

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;public class Main {//给定的10个ciphertext以及target ciphertextprivate final static String string_cipher_text01 = "315c4eeaa8b5f8aaf9174145bf43e1784b8fa00dc71d885a804e5ee9fa40b1" +"6349c146fb778cdf2d3aff021dfff5b403b510d0d0455468aeb98622b137dae857553ccd8883a7bc37520e06e515d22c954eba50";private final static String string_cipher_text02 = "234c02ecbbfbafa3ed18510abd11fa724fcda2018a1a8342cf064bbde548b12b07df" +"44ba7191d9606ef4081ffde5ad46a5069d9f7f543bedb9c861bf29c7e205132eda9382b0bc2c5c4b45f919cf3a9f1cb741"; private final static String string_cipher_text03 = "32510ba9a7b2bba9b8005d43a304b5714cc0bb0c8a34884dd91304b8ad40b62b07df" +"44ba6e9d8a2368e51d04e0e7b207b70b9b8261112bacb6c866a232dfe257527dc29398f5f3251a0d47e503c66e935de812";private final static String string_cipher_text04 = "32510ba9aab2a8a4fd06414fb517b5605cc0aa0dc91a8908c2064ba8ad5ea06a0290" +"56f47a8ad3306ef5021eafe1ac01a81197847a5c68a1b78769a37bc8f4575432c198ccb4ef63590256e305cd3a9544ee41";private final static String string_cipher_text05 = "3f561ba9adb4b6ebec54424ba317b564418fac0dd35f8c08d31a1fe9e24fe56808c2" +"13f17c81d9607cee021dafe1e001b21ade877a5e68bea88d61b93ac5ee0d562e8e9582f5ef375f0a4ae20ed86e935de812";private final static String string_cipher_text06 = "32510bfbacfbb9befd54415da243e1695ecabd58c519cd4bd2061bbde24eb76a19d8" +"4aba34d8de287be84d07e7e9a30ee714979c7e1123a8bd9822a33ecaf512472e8e8f8db3f9635c1949e640c621854eba0d";private final static String string_cipher_text07 = "32510bfbacfbb9befd54415da243e1695ecabd58c519cd4bd90f1fa6ea5ba47b01c9" +"09ba7696cf606ef40c04afe1ac0aa8148dd066592ded9f8774b529c7ea125d298e8883f5e9305f4b44f915cb2bd05af513";private final static String string_cipher_text08 = "315c4eeaa8b5f8bffd11155ea506b56041c6a00c8a08854dd21a4bbde54ce56801d9" +"43ba708b8a3574f40c00fff9e00fa1439fd0654327a3bfc860b92f89ee04132ecb9298f5fd2d5e4b45e40ecc3b9d59e941"; private final static String string_cipher_text09 = "271946f9bbb2aeadec111841a81abc300ecaa01bd8069d5cc91005e9fe4aad6e04d5" +"13e96d99de2569bc5e50eeeca709b50a8a987f4264edb6896fb537d0a716132ddc938fb0f836480e06ed0fcd6e9759f404";private final static String string_cipher_text10 = "466d06ece998b7a2fb1d464fed2ced7641ddaa3cc31c9941cf110abbf409ed395980" +"05b3399ccfafb61d0315fca0a314be138a9f32503bedac8067f03adbf3575c3b8edc9ba7f537530541ab0f9f3cd04ff50d";private final static String target_text          = "32510ba9babebbbefd001547a810e67149caee11d945cd7fc81a05e9f85aac650e90" +"52ba6a8cd8257bf14d13e6f0a803b54fde9e77472dbff89d71b57bddef121336cb85ccb8f3315f4b52e301d16e9f52f904";private final static String guest_key            = "66396e89c9dbd8cc9874352acd6395102eafce78aa7fed28a07f6bc98d29c50b69b0" +"339a19f8aa401a9c6d708f80c066c763fef0123148cdd8e802d05ba98777335daefcecd59c433a6b268b60bf4eF03C9A61";public static void main(String[] args) throws UnsupportedEncodingException {//将每一个ciphertext转换成为BigIntegerBigInteger[] bigIntegerText = {new BigInteger(string_cipher_text01,16),new BigInteger(string_cipher_text02,16),new BigInteger(string_cipher_text03,16),new BigInteger(string_cipher_text04,16),new BigInteger(string_cipher_text05,16),new BigInteger(string_cipher_text06,16),new BigInteger(string_cipher_text07,16),new BigInteger(string_cipher_text08,16),new BigInteger(string_cipher_text09,16),new BigInteger(string_cipher_text10,16)};BigInteger bigIntgerTargetText = new BigInteger(target_text,16);BigInteger bigIntegerGuestKey = new BigInteger(guest_key,16);for(int i=0;i<10;i++) {System.out.println(i+1+":\n" + new String(bigIntegerGuestKey.xor(bigIntegerText[i]).toByteArray(), "GBK"));}}
}

output:
1:
We can factor the number 15 with quantum computers. We can also factor the number 1
2:
Euler would probably enjoy that now his theorem becomes a corner stone of crypto -
3:
The nice thing about Keeyloq is now we cryptographers can drive a lot of fancy cars
4:
The ciphertext produced by a weak encryption algorithm looks as good as ciphertext
5:
You don’t want to buy a set of car keys from a guy who specializes in stealing cars
6:
There are two types of cryptography - that which will keep secrets safe from your l
7:
There are two types of cyptography: one that allows the Government to use brute for
8:
We can see the point where the chip is unhappy if a wrong bit is sent and consumes
9:
A (private-key) encryption scheme states 3 algorithms, namely a procedure for gene
10:
The Concise OxfordDictionary (2006) de铿乶es crypto as the art of writing o r sol

不知道第十个为什么会出来奇奇怪怪的东西 : (

密码学 (cryptography I - Dan Boneh) 【Week 1】Homework相关推荐

  1. 斯坦福Dan Boneh密码学——01 香农密码与完美安全

    斯坦福Dan Boneh密码学--01 香农密码与完美安全# 网安专硕,在导师推荐下,本周开始学习斯坦福大学Dan Boneh教授的密码学教材,全英文900页,密码学真的太难入门了..读教材的同时做了 ...

  2. 斯坦福Dan Boneh密码学——04 流密码

    斯坦福Dan Boneh密码学--04 流密码 密码学系列第四篇笔记 流密码 简单来说,流密码实现了我们构建使用合理短密钥的安全密码的目的. 伪随机生成器 回想一次性密码本,密钥.消息和密文都是L位字 ...

  3. 斯坦福Dan Boneh密码学——03 匿名路由

    斯坦福Dan Boneh密码学--03 匿名路由 这篇笔记的篇幅相对少一些,内容也比较好理解一些.实在不知道为什么Markdown语法写希腊字母本来格式好好的,转移到这边就变了.. 匿名路由 假如Al ...

  4. 斯坦福公开课 密码学 cryptography 1 思维导图

    本文是根据Stanford Univ. 公开课密码学1的整理而成的思维导图,该课程由大名鼎鼎的Dan Boneh教授的. 本人特别推荐这门公开课.虽然他讲话很快,但是语言表述清晰,而且很大部分已经有中 ...

  5. Dan Boneh密码学-01.绪论

    1.1引言 密码学--保护数据的常见工具,保护硬盘文件 (1)如何使用密码学原型(2)推导.构建加密机制的安全性 应用: web通信受HTTPS协议保护 无线流量的egWi-Fi 可使用WPA2协议保 ...

  6. Cryptography I 斯坦福大学 Dan Boneh——学习笔记1

    1.一次性密码本(One-time Pad:OTP)(Vernam 1917) E(k,m) = m ⊕ k , D(k,c) = c ⊕ k Given a message (m) and its ...

  7. 浅谈零知识证明之二:简短无交互证明(SNARK)

    本文作者东泽,来自安比技术社区的小伙伴,目前就读于斯坦福大学,研究方向密码学,本系列文章来源于作者在斯坦福著名的课程<CS 251: Cryptocurrencies and blockchai ...

  8. 骄傲! 咱中国人的区块链技术闯进了国际学术顶会!

    作者 | 王嘉平  创新工场执行董事 责编 | 佩奇 出品 | 区块链大本营(blockchain_camp) 上周我从美国的西北角西雅图飞到了东北角波士顿,在那里待了几天,为了参加 USENIX的旗 ...

  9. 零知识证明学习笔记:背景与起源

    副标题:斯坦福学霸的零知识证明学习笔记(一) 本文作者东泽,来自安比技术社区的小伙伴,目前就读于斯坦福大学,研究方向密码学,本系列文章来源于作者在斯坦福著名的课程<CS 251: Cryptoc ...

最新文章

  1. html传參中?和amp;
  2. 一意孤行,360继续奉行互联网恐怖主义
  3. 基于Elasticsearch实现搜索推荐
  4. idea中新建分支并且切换到新建的分支上
  5. linux 脚本中的push,linux shell之pushd、popd和dirs的使用讲解
  6. 数组copyWithin()方法以及JavaScript中的示例
  7. 王道计算机考研课件,王道考研计算机组成原理课件ppt
  8. 西瓜书《机器学习》决策树IDW3, C4.5公式推导
  9. Inno Setup 系列之自定义卸载文件名称的脚本
  10. 共享茶室小程序开发解决方案
  11. 8串口服务器芯片,塔石串口服务器的芯片W7500
  12. sonar代码质量分析
  13. python操作gif 图片拆分
  14. 计算机网络面试常见问题
  15. python编程:从入门到实践 阅读笔记
  16. 高速公路交警的经验之谈[转自QQ群]
  17. 如何解决‘CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate’错误
  18. Socks代理上网工具 tsocks
  19. CentOS7安装Jenkins教程
  20. FormData的用途

热门文章

  1. Redis的持久化技术原理及选型
  2. SmallJava产品说明书(20210417)
  3. Labelmx条码软件---二维码名片的制作教程
  4. python3从零学习-5.5.4、xdrlib — 编码与解码 XDR 数据
  5. 使用 Docker 搭建你的Wiki(TiddlyWiki)
  6. eshop6-nginx
  7. 山寨精神确实很吊---编程累了大家来放松一下:)
  8. SpringBoot+Redis完成数据缓存(内容丰富度一定超出你的想象)
  9. 二维码及其图片页面展示
  10. 烟台大学计算机学院考研成果,2020年烟台大学计算机科学与技术考研经验分享...