密码学

https://blog.csdn.net/sinat_25449961/article/details/56279952

凯撒密码

for shift in range(26):
    str = r"YSMWGTZOGVWGTNGHAOB"
    new_str = ''
    for i in str:
        if i >= 'A' and i <= 'Z':  # or i>='A'and i<='Z':
            i = ord(i)
            i = ((i + shift) - 97) % 26 + 97
            i = chr(i)
        new_str = new_str + i
    print(new_str)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

替代密码

http://quipqiup.com/

维吉尼亚加密

在凯撒密码基础之上的加密方式,添加了密钥的概念

例如明文:TO BE OR NOT TO BE THAT IS THE QUESTION 
密钥: RELATIONS

加密过程如下: 
《密码学》
《密码学》
《密码学》

Base64编码

base64是一种用64个字符来表示任意二进制数据的方法。(因为2的6次方为64)

base64编码要求把3个8位字节(3*8=24)转化为4个6位字节(4*6=24),之后在6位字节的前面补两个0,形成新的8位字节。如果剩下的字符不足3个字节,则用0填充,输出字符试用‘=’,因此编码后输出带文本末尾可能会出现一个或两个‘=’。

import base64
print base64.b64decode('dGhpc2lzYW5hcHBsZQ==')
print base64.b64encode('thisisanapple')
  • 1
  • 2
  • 3

ascii码

ascii,是基于拉丁字母的一套电脑编码系统

对照表:http://tool.oschina.net/commons?type=4

print ord('a')
print chr(97)
  • 1
  • 2

ROT13加密

rot13是一种简易的置换,将26个字母的前半部分与后半部分相互交换,如‘a’<=>’n’,’b’<==>’o’

《密码学》

def rot13(s, OffSet=13):
    def encodeCh(ch):
        f = lambda x: chr((ord(ch) - x + OffSet) % 26 + x)
        return f(97) if ch.islower() else (f(65) if ch.isupper() else ch)

    return ''.join(map(encodeCh, s))


s = 'Hello!'
print rot13(s)  # Uryyb!
print rot13(rot13(s))  # Hello!
print rot13(s, 13)  # Hello!
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

莫斯密码

http://www.zhongguosou.com/zonghe/moErSiCodeConverter.aspx

CODE = {'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': '--..',

        '0': '-----', '1': '.----', '2': '..---',
        '3': '...--', '4': '....-', '5': '.....',
        '6': '-....', '7': '--...', '8': '---..',
        '9': '----.'
        }


def main():
    msg = raw_input('MESSAGE: ')
    for char in msg:
        if char == ' ':
            print
        else:
            print CODE[char.upper()] + ' ',


if __name__ == "__main__":
    main()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

手机按键

《密码学》 
21表示a,22表示b,51表示j,依此类推。

当铺密码

《密码学》

这尼玛有什么蛋用?

矩阵加密

下图为5*5矩阵加密 
《密码学》

11表示A,12表示B,依次类推。

栅栏加密

一般比较常见的是2栏的栅栏密码。 
比如明文:THEREISACIPHER 
两个一组,得到:TH ER EI SA CI PH ER 
先取出第一个字母:TEESCPE 
再取出第二个字母:HRIAIHR 
连在一起就是加密的内容:TEESCPEHRIAIHR 
而解密的时候,我们先把密文从中间分开,变为两行: 
T E E S C P E 
H R I A I H R 
再按上下上下的顺序组合起来: 
THEREISACIPHER

希尔密码

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from numpy.ma import array

__Url__ = 'Http://www.purpleroc.com'
__author__ = 'Tracy_梓朋'
from numpy import *
Dic = {chr(i+97):i for i in range(26)}
def decode(pwd, org):
    temp = []
    result = []
    while True:
        if len(pwd) % 3 != 0:
            pwd.append(pwd[-1])
        else:
            break
    for i in pwd:
        temp.append(Dic.get(i))
    temp = array(temp)
    temp = temp.reshape(len(pwd)/3, 3)
    #print temp
    #print org
    xx = matrix(temp)*org
    for j in range(len(pwd)/3):
        for i in range(3):
            if (int(xx[j, i]) >= 26):
                result.append(chr(xx[j, i] % 26 + 97))
                #print xx[j, i] % 26
            else:
                #print xx[j, i]
                result.append(chr(xx[j, i] + 97))
    return result
def get_vmatrix(org):
    org_adjoin = org.I*linalg.det(org)
    print org_adjoin
    org_det = int(str(abs(linalg.det(org))).split('.')[0])
    print org_det
    for i in range(1, 26):
        if i * org_det % 26 == 1:
            break
    org_mod = -org_adjoin * i % 26
    org_mod = matrix(org_mod)
    temp = []
    for i in range(org_mod.shape[0]):
        for j in range(org_mod.shape[1]):
            temp.append(int(str(org_mod[i, j]).split('.')[0]))
    org_final = matrix(temp).reshape(org_mod.shape[0], org_mod.shape[1])
    #print org_final
    return org_final
if __name__ == '__main__':
    ''' for test pwd = list("act") org = matrix(array([[6, 24, 1], [13 , 16, 10], [20, 17, 15]])) result = decode(pwd, org) print "".join(result) deorg = matrix(array([[8, 5, 10], [21 , 8, 21], [21, 12, 8]])) result = decode(result, deorg) print "".join(result) '''
    pwd = "wjamdbkdeibr"
    pwd = list(pwd)
    org = matrix(array([[1,2,3],[4,5,6],[7,8,10]]))
    org_vm = get_vmatrix(org)
    print org_vm
    print "Your flag is :" + "".join(decode(pwd, org_vm))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65

JSFuck

JSFuck 可以让你只用 6 个字符 !+ 来编写 JavaScript 程序。 
http://www.jsfuck.com/ 
http://patriciopalladino.com/files/hieroglyphy/

培根密码

使用a和b或其他方式代表0和1的二进制

例如:密文是LOVE,采用大小写进行二进制的区分,并且采用“随意选取句子和文”加密,得到结果就是“SuIyI XuaNq uJUzi HEwEN”

CRC校验

CRC是为了保证数据的正确采用的一种检错的手段。在诸多检错手段中,CRC是最著名的一种。CRC的全称是循环冗余校验。

import zlib

def crc32(st):
    crc = zlib.crc32(st)
    if crc > 0:
        return "%x" % (crc)
    else:
        return "%x" % (~crc ^ 0xffffffff)

print crc32('20190804')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

Brainfuck/Ook!

++++++++++[>+++++++>++++++++++>+++>+<<<<-]
>++.>+.+++++++..+++.>++.<<+++++++++++++++.
>.+++.------.--------.>+.>.
  • 1
  • 2
  • 3
Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook! Ook! Ook. Ook? Ook. Ook. Ook. Ook.
  • 1

https://www.splitbrain.org/services/ook

猪圈密码/共济会密码

《密码学》

转义工具

http://tool.oschina.net/encode

    原文作者:维吉尼亚加密问题
    原文地址: https://blog.csdn.net/qq_25987491/article/details/80198624
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞