The Imitation Game

《The Imitation Game》是一部非常好的电影,讲述了人工智能之父——阿兰图灵的传奇一生。
重点讲述了他通过破译德国的通讯密码缩短了二战的持续时间,因而拯救了无数生命的伟大事迹。
强烈推荐大家去看一看,这可是豆瓣评分8.6的好片啊!
另外,《The Imitation Game》也是当年图灵发表的关于他对人工智能看法的论文。链接在此
德国当时的加密方式叫Enigma,具体是怎样的加密机制呢?图灵面临了怎样的挑战呢?
POJ 1449给了我们一次亲身体验破解Enigma的机会。
代码如下:
#include <cstdio>
#include <cstring>
using namespace std; #define D(x) int f[][];
int g[][];
int state[];
int cipher[];
int plain[];
int len;
int *mark[];
int mark_num;
bool ok;
int power[] = {, , * , * * }; int get_next(int a[])
{
char st[];
scanf("%s", st);
for (int i = ; st[i]; i++)
{
if (st[i] == '?')
{
a[i] = -;
mark[mark_num++] = &a[i];
continue;
}
a[i] = st[i] - 'a';
}
return strlen(st);
} void input()
{
mark_num = ;
for (int i = ; i < ; i++)
{
get_next(f[i]);
}
get_next(state);
len = get_next(plain);
get_next(cipher);
} void output()
{
for (int i = ; i < len; i++)
{
putchar(plain[i] + 'a');
}
puts("");
} int encrypt(int a, int pos)
{
int temp = f[][a];
int cur_state[];
int delta[]; for (int i = ; i < ; i++)
{
cur_state[i] = state[i] + pos / power[i];
cur_state[i] = (cur_state[i] + ) % ;
}
delta[] = cur_state[];
for (int i = ; i < ; i++)
{
delta[i] = (cur_state[i] - cur_state[i - ] + ) % ;
} for (int i = ; i < ; i++)
{
temp = f[i][(temp + delta[i] + ) % ];
} for (int i = ; i >= ; i--)
{
temp = g[i][(temp - delta[i + ] + ) % ];
} temp = g[][(temp - delta[] + ) % ];
return temp;
} bool check()
{
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
g[i][f[i][j]] = j;
}
} for (int i = ; i < len; i++)
{
if (encrypt(plain[i], i) != cipher[i])
{
return false;
}
}
return true;
} void dfs(int step)
{
if (ok)
{
return;
}
if (step == mark_num)
{
if (check())
{
ok = true;
output();
}
return;
}
for (int i = ; i < ; i++)
{
*mark[step] = i;
dfs(step + );
}
} void test(char a, int b)
{
check();
printf("%c %c\n", a, encrypt(a - 'a', b) + 'a');
} int main()
{
int t;
scanf("%d", &t);
for (int i = ; i <= t; i++)
{
printf("Scenario #%d:\n", i);
input();
ok = false;
dfs();
D(test('a', ));
puts("");
}
return ;
}
The Imitation Game的更多相关文章
- 深度学习课程笔记(七):模仿学习(imitation learning)
深度学习课程笔记(七):模仿学习(imitation learning) 2017.12.10 本文所涉及到的 模仿学习,则是从给定的展示中进行学习.机器在这个过程中,也和环境进行交互,但是,并没有显 ...
- #英文#品读中国城市个性——最好的和最坏的&当东方遇到西方
冒险家的乐园 a playground of risk 实现发财梦 realize one's dreams of wealth 道德沦丧,堕落 moral deprivation 租界 foreig ...
- Unix及类Unix系统文本编辑器的介绍
概述 Vim是一个类似于Vi的著名的功能强大.高度可定制的文本编辑器,在Vi的基础上改进和增加了很多特性.VIM是纯粹的自由软件. Vim普遍被推崇为类Vi编辑器中最好的一个,事实上真正的劲敌来自Em ...
- iOS开发之开源项目链接
1. Coding iOS 客户端 Coding官方客户端. 笔者强烈推荐的值得学习的完整APP.GitHub - Coding/Coding-iOS: Coding iOS 客户端源代码 2. OS ...
- AssetBundle loading failed because.....已解决
http://blog.csdn.net/ldghd/article/details/9632455 ***************************** 一 ******* ...
- 【Python + Selenium】Mock Testing 是啥?一个so上的高票答案。
There are many kinds of testing which really made me confused. To be honest, I've never heard of som ...
- 深度|OpenAI 首批研究成果聚焦无监督学习,生成模型如何高效的理解世界(附论文)
本文经机器之心(微信公众号:almosthuman2014)授权转载,禁止二次转载,原文. 选自 Open AI 作者:ANDREJ KARPATHY, PIETER ABBEEL, GREG BRO ...
- vim深入研究
About VIM--Unix及类Unix系统文本编辑器 Vim是一个类似于Vi的著名的功能强大.高度可定制的文本编辑器,在Vi的基础上改进和增加了很多特性.VIM是纯粹的自由软件. Vim普遍被推崇 ...
- GitHub 上有哪些完整的 iOS-App 源码值得参考?
1. Coding iOS 客户端 Coding官方客户端. 笔者强烈推荐的值得学习的完整APP.GitHub - Coding/Coding-iOS: Coding iOS 客户端源代码 2. OS ...
随机推荐
- 初识ActionScript
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:fx="h ...
- DNX 版本升级命令
一.稳定版本 dnvm install latest -a x86 -r clrdnvm install latest -a x86 -r coreclrdnvm install latest -a ...
- 存储过程中的when others then 和 raise
EXCEPTION when others then rollback; dbms_output.put_line('code:' || sqlcode); dbms_output.put_line( ...
- recording just for inquiry in the future
auditd审计 相关命令有: auditd, auditctl, ausearch, aureport 相关文件: /etc/audit/auditd.conf, /etc/audit/audit. ...
- PostgreSQL中的时间操作总结
取当前日期的函数: (1) 取当前时间:select now() (2) 取当前时间的日期: select current_date (3) 取当前具体时间(不含日 ...
- 移动WebApp利用Chrome浏览器进行调试
详细的请看这个(HBuilder是我长期使用,而且值得支持的国内前端开发编辑器) http://ask.dcloud.net.cn/article/151 http://ask.dcloud.net. ...
- 深度剖析:如何实现一个 Virtual DOM 算法
本文转载自:https://github.com/livoras/blog/issues/13 目录: 1 前言 2 对前端应用状态管理思考 3 Virtual DOM 算法 4 算法实现 4.1 步 ...
- CSS vertical-align 属性
定义和用法 vertical-align 属性设置元素的垂直对齐方式.该属性定义行内元素的基线相对于该元素所在行的基线的垂直对齐
- CSS3必须要知道的10个顶级命令
1.边框圆角(Border Radiuas) 这个是我们在平常很常用的吧,以前我在用div圆角的时候,特别特别的痛苦,不管是用CSS来画圆角,还是用图片来画圆角都不那么容易,但是现在好了,在CSS3中 ...
- scanf函数与输入缓冲区
本文链接:http://www.cnblogs.com/xxNote/p/4008668.html 今天看书的时候遇到scanf函数与缓冲区的问题,产生了一些猜想即:应该有一个指针来记录缓冲区中读取到 ...