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[6][30];
int g[6][30];
int state[6];
int cipher[90];
int plain[90];
int len;
int *mark[3];
int mark_num;
bool ok;
int power[] = {1, 26, 26 * 26, 26 * 26 * 26};

int get_next(int a[])
{
    char st[90];
    scanf("%s", st);
    for (int i = 0; st[i]; i++)
    {
        if (st[i] == ‘?‘)
        {
            a[i] = -1;
            mark[mark_num++] = &a[i];
            continue;
        }
        a[i] = st[i] - ‘a‘;
    }
    return strlen(st);
}

void input()
{
    mark_num = 0;
    for (int i = 0; i < 5; i++)
    {
        get_next(f[i]);
    }
    get_next(state);
    len = get_next(plain);
    get_next(cipher);
}

void output()
{
    for (int i = 0; i < len; i++)
    {
        putchar(plain[i] + ‘a‘);
    }
    puts("");
}

int encrypt(int a, int pos)
{
    int temp = f[4][a];
    int cur_state[4];
    int delta[4];

    for (int i = 0; i < 4; i++)
    {
        cur_state[i] = state[i] + pos / power[i];
        cur_state[i] = (cur_state[i] + 26) % 26;
    }
    delta[0] = cur_state[0];
    for (int i = 1; i < 4; i++)
    {
        delta[i] = (cur_state[i] - cur_state[i - 1] + 26) % 26;
    }

    for (int i = 0; i < 4; i++)
    {
        temp = f[i][(temp + delta[i] + 26) % 26];
    }

    for (int i = 2; i >= 0; i--)
    {
        temp = g[i][(temp - delta[i + 1] + 26) % 26];
    }

    temp = g[4][(temp - delta[0] + 26) % 26];
    return temp;
}

bool check()
{
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 26; j++)
        {
            g[i][f[i][j]] = j;
        }
    }

    for (int i = 0; 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 = 0; i < 26; i++)
    {
        *mark[step] = i;
        dfs(step + 1);
    }
}

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 = 1; i <= t; i++)
    {
        printf("Scenario #%d:\n", i);
        input();
        ok = false;
        dfs(0);
        D(test(‘a‘, 1));
        puts("");
    }
    return 0;
}

时间: 2024-08-12 01:58:10

The Imitation Game的相关文章

On Imitation monkey the assignment is usually to carry a variety of major model low cost diesel-engined wristwatches

This wristwatches are made to glimpse very much like the genuine wristwatches in order to retain each of the efficiency. On Imitation monkey the assignment is usually to carry a variety of major model low cost diesel watches outlet within just one ro

深度强化学习之:模仿学习(imitation learning)

深度强化学习之:模仿学习(imitation learning) 2017.12.10 本文所涉及到的 模仿学习,则是从给定的展示中进行学习.机器在这个过程中,也和环境进行交互,但是,并没有显示的得到 reward.在某些任务上,也很难定义 reward.如:自动驾驶,撞死一人,reward为多少,撞到一辆车,reward 为多少,撞到小动物,reward 为多少,撞到 X,reward 又是多少,诸如此类...而某些人类所定义的 reward,可能会造成不可控制的行为,如:我们想让 agent

Learning How to Actively Learn: A Deep Imitation Learning Approach

Learning How to Actively Learn: A Deep Imitation Learning Approach 2019-07-15 23:00:16 Paper: https://www.aclweb.org/anthology/P18-1174 Code: https://github.com/Grayming/ALIL 1. Background and Motivation: 待更新 ... 原文地址:https://www.cnblogs.com/wangxiao

【 李宏毅深度学习合辑 】Advanced Topics in Deep Learning - Imitation Learning

You have to force experts to treat some uncommon and extreme situations. a mechanical way to learn However, we don't know rt if you use sequence GAN, you could get different D(taoi) in different steps. However here, it remains the same. 原文地址:https://

根据76大细分词性对单词进行归组(二)

词性的重要性不言而喻,尤其是对于自然语言处理来说,哪怕就是记单词,根据词性对单词进行归组也是非常有帮助的. superword是一个Java实现的英文单词分析软件,主要研究英语单词音近形似转化规律.前缀后缀规律.词之间的相似性规律等等. 各大词性及其包括的词: 32.N-COUNT-COLL(可数集合名词) (词数:50) 1 aristocracy army array audience band 2 cast chapter command commission committee 3 co

词组习语3057组

superword是一个Java实现的英文单词分析软件,主要研究英语单词音近形似转化规律.前缀后缀规律.词之间的相似性规律等等. 1 Anointing of the Sick British English 2 Civvy Street Clerk of the Closet 3 I mean I must say 4 I suppose so I will thank you to do something 5 Incoming mail server Lithium battery 6 M

【转帖】Bootleg recording

Bootleg recording From Wikipedia, the free encyclopedia For other uses, see Bootleg (disambiguation). The audio cassette greatly increased the distribution of bootleg recordings in the 1980s. A bootleg recording is an audio or video recording of a pe

Java核心 --- 枚举

Java核心 --- 枚举 枚举把显示的变量与逻辑的数字绑定在一起在编译的时候,就会发现数据不合法也起到了使程序更加易读,规范代码的作用 一.用普通类的方式实现枚举 新建一个终态类Season,把构造方法设为私有,因为枚举值不能随意增加因为不能new出这个类的对象,所以需要定义成员变量,把new写在类的内部这样,就可以在类的外部通过访问类的静态成员变量的方式访问到枚举值通过这样的方式,只能在类的外部使用在枚举类的内部定义的枚举值 类Season里面是可以有方法的,我们设置地球又公转了四分之一方法

【JavaScript】你知道吗?Web的26项基本概念和技术

Web开发是比较费神的,需要掌握很多很多的东西,特别是从事前端开发的朋友,需要通十行才行.今天,本文向初学者介绍一些Web开发中的基本概念和用到的技术,从A到Z总共26项,每项对应一个概念或者技术. A — AJAX AJAX 全称为“Asynchronous JavaScript and XML”(异步JavaScript和XML),是一种创建交互式网页应用的网页开发技术.根据Ajax提出者Jesse James Garrett建议,AJAX: 使用XHTML+CSS来表示信息: 使用Java