Easy Cipher Decryption

Copyright © 2018 Joyce_BY
All rights reserved.
Contact by Yagnes126@gmail.com


caesar cipher / shift cipher / Caesar’s cipher / Caesar’s code / Caesar shift

It is a type of substitution cipher, each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on.

Decryption code is as followed:

	# !/usr/bin/python
	# python 3.7.0
	# encode -- UTF-8 --
	# authorized by Joyce_BY, all rights reserved.

	# caesar cipher
	c = input("input the ciphertext to decrypt: ")
	cipher  = c.split(' ')
	for i in range(26): 
	    plain = []
	    for item in cipher: 
	        m = []
	        for ch in item: 
	            m.append(chr((ord(ch)+i) % 26))
	        plain.append(''.join(m))  
	    print(' '.join(plain))

 

vigenere cipher

Find details in my another blog: Hacking Vigenère Cipher

hill cipher

Find details in my another blog: Hill Cipher and a Variant

 

bacon’s cipher

To encode a message, each letter of the plaintext is replaced by a group of five of the letters ‘A’ or ‘B’. This replacement is a binary encoding and is done according to the alphabet of the Baconian cipher.
There are 2 scheme, shown below:

Scheme1

LetterCodeBinary
Aaaaaa00000
Baaaab00001
Caaaba00010
Daaabb00011
Eaabaa00100
Faabab00101
Gaabba00110
Haabbb00111
I,Jabaaa01000
Kabaab01001
Lababa01010
Mababb01011
Nabbaa01100
Oabbab01101
Pabbba01110
Qabbbb01111
Rbaaaa10000
Sbaaab10001
Tbaaba10010
U,Vbaabb10011
Wbabaa10100
Xbabab10101
Ybabba10110
Zbabbb10111

Scheme2

LetterCodeBinary
Aaaaaa00000
Baaaab00001
Caaaba00010
Daaabb00011
Eaabaa00100
Faabab00101
Gaabba00110
Haabbb00111
Iabaaa01000
Jabaab01001
Kababa01010
Lababb01011
Mabbaa01100
Nabbab01101
Oabbba01110
Pabbbb01111
Qbaaaa10000
Rbaaab10001
Sbaaba10010
Tbaabb10011
Ubabaa10100
Vbabab10101
Wbabba10110
Xbabbb10111
Ybbaaa11000
Zbbaab11001

code is shown below:

# !/usr/bin/python
# python 3.7.0
# environment: windows 10
# encode -- UTF-8 --
# authorized by Joyce_BY, all rights reserved.
# contact by email: Yagnes0126@gmail.com

# bacon cipher decryption
# notice that 'A' to 'a', 'a' to 'A' !!

# Scheme 1
dic = { 'aaaaa':'a','aaaab':'b','aaaba':'c','aaabb':'d','aabaa':'e','aabab':'f','aabba':'g','aabbb':'h','abaaa':'i','abaaa':'j',
        'abaab':'k','ababa':'l','ababb':'m','abbaa':'n','abbab':'o','abbba':'p','abbbb':'q','baaaa':'r','baaab':'s','baaba':'t',
        'baabb':'u','baabb':'v','babaa':'w','babab':'x', 'babba':'y','babbb':'z'}

# Scheme2
dic = { 'aaaaa':'a','aaaab':'b','aaaba':'c','aaabb':'d','aabaa':'e','aabab':'f','aabba':'g','aabbb':'h','abaaa':'i','abaab':'j',
        'ababa':'k','ababb':'l','abbaa':'m','abbab':'n','abbba':'o','abbbb':'p','baaaa':'q','baaab':'r','baaba':'s','baabb':'t',
        'babaa':'u','babab':'v','babba':'w','babbb':'x','bbaaa':'y','bbaab':'z'}

def patter_change(sstr,a,b):
    ch_str = []
    for ch in sstr:
        if ch == a: 
            ch_str.append('a')
        else: 
            ch_str.append('b')
    s = ''.join(ch_str)
    return s

def decode(sstr):
    d1 = []
    d2 = []
    for i in range(len(sstr) // 5): 
        substr = sstr[:5]
        sstr = sstr[5:]
        d1.append(dic1[substr])
        d2.append(dic2[substr])
    return ''.join(d1), ''.join(d2)
    
if __name__ == '__main__':
    string = input('input the string to decode: ')
    c = string.split(' ')
    m1 = []
    m2 = []
    for item in c: 
        temp = patter_change(item,'c','d')
        t1,t2 = decode(temp)
        m1.append(t1)
        m2.append(t2)
    print("By scheme1: ", (' '.join(m1)).upper())
    print("By scheme2: ", (' '.join(m2)).upper())

 

当铺密码

当铺密码是一种将中文和数字进行转化的密码, 当前汉字有多少笔画出头,就转化成数字几。
例如:
王夫 井工 夫口 由中人 井中 夫夫 由中大:67 84 70 123 82 77 125
==> CTF{RM}

 

Morse Code

Morse code is a method of transmitting text information as a series of on-off tones, lights, or clicks that can be directly understood by a skilled listener or observer without special equipment.

# !/usr/bin/python
# python 3.7.0
# environment: windows 10
# encode -- UTF-8 --
# authorized by Joyce_BY, all rights reserved.
# contact by email: Yagnes0126@gmail.com

# morse code decryption

a = input("Input your ciphertext: ")
s = a.split(' ')
# International standard dictionary
dic = { '.-': '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',
        '..---': '2',
        '...--': '3',
        '....-': '4',
        '.....': '5',
        '-....': '6',
        '--...': '7',
        '---..': '8',
        '----.': '9',
        '-----': '0',
        '..--..': '?',
        '-..-.': '/',
        '-.--.-': '()',
        '-....-': '-',
        '.-.-.-': '.',
        '..--.-': ' ',
        '/': ' '
    }
decode = []
for item in s:
    decode.append(dic[item])
print((''.join(decode)).lower())
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值