Homework1
来源:互联网 发布:mac销量 编辑:程序博客网 时间:2024/06/07 04:01
Homework1
1.Prove or refute: Every encryption scheme for which the size of the key space equals the size of the message space, and for which the key is chosen uniformly from the key space, is perfectly secret.
Solution:
The statement is false.
Consider an encryption scheme (Gen,Enc,Dec) whose key space and message space are both
The equality means that we don’t use
2.Let
(a) Define
Solution:
Not necessarily.We can construct a special kind of pseudorandom generator
Let
Then we can get a
However, if we consider
3. Write a program to achieve a one time pad.
Solution:
#include "randpool.h"#include <iostream>using namespace std;using namespace CryptoPP;#pragma comment(lib, "cryptlib.lib")RandomPool & GlobalRNG();int main(){ const char* list = "helloworld"; int len = strlen(list); int *lis = new int[len]; int *key = new int[len]; int *rst = new int[len]; char *keyc = new char[len + 1]; char *rstc = new char[len + 1]; for (int i = 0; i < len; i++) { lis[i] = list[i] - 'a'; } for (int i = 0; i < len; i++) { int a = GlobalRNG().GenerateByte() % 26; key[i] = a; keyc[i] = (char)('a' + a); int b = a^lis[i]; rst[i] = b; rstc[i] = (char)('a' + b % 26); } keyc[len] = '\0'; rstc[len] = '\0'; cout << "The generated key is " << keyc << endl; cout << "The encrypted string is " << rstc << endl; char* dec = new char[len + 1]; for (int i = 0; i < len; i++) { int t = key[i] ^ rst[i]; dec[i] = (char)('a' + t); } dec[len] = '\0'; cout << "The decrypted message is " << dec << endl; system("pause");}RandomPool & GlobalRNG(){ static RandomPool randomPool; return randomPool;}
The result is as following:
- Homework1
- homework1
- homework1
- homework1
- homework1
- 密码学 homework1
- Homework1-15
- 补充homework1
- C homework1
- data science cs109 homework1
- CSIT571: Cryptography and Security Homework1
- CSIT 561 Computer Networks: An Internet Perspective Homework1
- Paradigms Homework1 一个超小型二元一次方程组计算器
- UC Berkeley CS 61B 2014 Spring Homework1
- 磁臂调度算法
- 关于essay的使用问题
- geodatabase中如何获取feature class的ObjectID
- Attention model 的一些概念
- 51nod 1515:明辨是非 并查集合并
- Homework1
- 自动化测试软件UFT实验
- PostgreSQL (User defined Operator) UDO & Operator Optimization Information
- android sqlite的SqliteDataBase.insert()方法,以及如何在事务管理中使用
- Caffe matlab之基于Alex network的特征提取
- Word2Vec
- iOS8中使用CoreLocation定位
- 在linux系统中安装MySQL
- Eclipse操作技巧