美文网首页
hill小记

hill小记

作者: BuFFERer | 来源:发表于2018-11-01 00:31 被阅读0次

    今天西南民大的老哥,发我一道i春秋上的题,题目名字over the hill,然后就有了这篇,也是第一篇。

    先介绍一下hill,Hill 密码是一种多字母代替密码。Hill 密码要求首先将明文分成同等规模的若干个分组(最后一个分组不足时需要填充),每一个分组被整体加密变换,即 Hill 密码属于分组加密

    加密过程~!

    先将26个英文字母用0-25进行编号。


    下面用两个题,来介绍两个师傅的脚本。

    一、安恒杯的一道月赛--爬坡道

    经过一系列操作,步骤省略,得到最重要的内容

    矩阵:

    3   1

    2   1

    密文:

    mttpjbpexfdzcegtdzeanutg

    这里贴一个师傅的脚本,c语言版。

    链接:https://pan.baidu.com/s/1WjzDJaSHGB2JmA79VLfHQQ

    提取码:1f3g

    二、i春秋--over the hill

    下面是师傅的脚本

    import numpy

    from sage.all import *

    alphabet = ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789_{}")

    n = len(alphabet)

    Zn = IntegerModRing(n)

    secret  = [[54, 53, 28, 20, 54, 15, 12, 7],

              [32, 14, 24, 5, 63, 12, 50, 52],

              [63, 59, 40, 18, 55, 33, 17, 3],

              [63, 34, 5, 4, 56, 10, 53, 16],

              [35, 43, 45, 53, 12, 42, 35, 37],

              [20, 59, 42, 10, 46, 56, 12, 61],

              [26, 39, 27, 59, 44, 54, 23, 56],

              [32, 31, 56, 47, 31, 2, 29, 41]]

    secret = matrix(Zn, secret).inverse()

    ciphertext = "7Nv7}dI9hD9qGmP}CR_5wJDdkj4CKxd45rko1cj51DpHPnNDb__EXDotSRCP8ZCQ"

    blocks = [ciphertext[i : i + secret.ncols()] for i in range(0, len(ciphertext), secret.ncols())]

    plaintext = ''

    for block in blocks:

        decrypted_block = secret * matrix(Zn, [alphabet.find(c) for c in block]).transpose()

        plaintext +=  ''.join(alphabet[int(i[0])] for i in decrypted_block)

    print plaintext

    在线运行网站:http://sagecell.sagemath.org/

    到这里就结束了,脚本都是师傅们的,很惭愧,共勉吧。

    over

    相关文章

      网友评论

          本文标题:hill小记

          本文链接:https://www.haomeiwen.com/subject/tyzdtqtx.html