谁能告诉我这个密码的名字好吗?

时间:2013-12-11 12:15:23

标签: encoding encode encryption substitution

有人能告诉我这个密码的名字吗?

我知道这是一个简单的替换密码,我只是不知道它的名字。

密钥:

help

密码字母:

a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z
h|e|l|p|a|b|c|d|f|g|i|j|k|m|n|o|q|r|s|t|u|v|w|x|y|z

文本:

this is a test

密文:

tdfs fs h tast

2 个答案:

答案 0 :(得分:1)

这不仅仅是一个简单的substitution cipher吗?您刚刚将“帮助”的4个字母移到前面,并将所有剩余的字母移到右侧。

修改

这是python中的一个实现,作为lambda,itertools和star(*)参数的练习,浪费时间(也许是为了拯救python中编码密码的有趣讨论):

import string
from itertools import izip, count, starmap

def cipher(s,key):
    # characters you want to translate, e.g.
    # 'abcd ... xyz '
    raw = string.ascii_lowercase + ' '

    # cipher with your key, e.g.
    # 'helpabcdfgi...z '
    sub = key + string.translate(raw, None, key)

    # create a dictionary from a character to an index
    # in the original raw value string
    m = dict( izip( raw, count() ) )

    # looks up the index in the map using: starmap(m.get, s)
    # then gets the substitution character: map( lambda i:sub[i], ...)
    # and joins them together
    return ''.join( map( lambda i:sub[i], starmap( m.get, s ) ))

一些测试代码可以验证它的工作原理:

ins = 'this is a test'
outs = cipher(ins, "help") 

print ins,' -> ',outs

exp = "tdfs fs h tast"
if exp == outs:
    print "pass :)"
else:
    print "~~ FAIL ~~", " expected ", exp

输出:

D:\temp>cipher.py
this is a test  ->  tdfs fs h tast
pass :)

答案 1 :(得分:0)

我想我找到了答案。凯撒变种,“混合字母”替代密码。

简单的是,但是为了增加复杂性,你可以将它放在这样的块中(成为混合字母和多字母的混合):

  |a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z
------------------------------------------------------
 1|h|e|l|p|a|b|c|d|f|g|I|j|k|m|n|o|q|r|s|t|u|v|w|x|y|z
 2|e|l|p|a|b|c|d|f|g|I|j|k|m|n|o|q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b|c|d|f|g|I|j|k|m|n|o|q|r|s|t
22|v|w|x|y|z|h|e|l|p|a|b|c|d|f|g|I|j|k|m|n|o|q|r|s|t|u
23|w|x|y|z|h|e|l|p|a|b|c|d|f|g|I|j|k|m|n|o|q|r|s|t|u|v
24|x|y|z|h|e|l|p|a|b|c|d|f|g|I|j|k|m|n|o|q|r|s|t|u|v|w
25|y|z|h|e|l|p|a|b|c|d|f|g|I|j|k|m|n|o|q|r|s|t|u|v|w|x
26|z|h|e|l|p|a|b|c|d|f|g|I|j|k|m|n|o|q|r|s|t|u|v|w|x|y

这将是一个Vigenere Cipher变体而不是Caesar Cipher变体。

仍然使用密钥:

help

同样的消息:

this is a test

会变成:

tfiv kx c hkep

另一个复杂程度是将字母全部组合在一起或组成块:

tfivkxchkep

或被屏蔽(3个字符):

tfi
vkx
chk
epz

    With an extra z added to make up the missing character.
相关问题