caesar brute force

| 标签 cryptography 

0x00 Caesar encryption

之前玩 ctf 遇到的这个类型题目, 于是写个脚本来破解, 暴力破解相对猜 key 来说简单一些, 所有脚本只支持暴力破解, 不过算法可以单独取出来用, 需者自取 1.

0x01 implementation

关于这个密码故事参考 2.

#!/usr/bin/python3

'''
This script for Caesar brute decryption.
'''
__author__ = "Sn0rt@abc.shop.edu.cn"
import string

MAX_KEY_SZIE = 26

def get_message():
    print('enter you message: ')
    return input().lower()

def brute(message):
    for key in range(1, MAX_KEY_SZIE + 1):
        print("%s" % decryption(key, message))

def decryption(key, message):
    key = 0 - key
    transled = ''
    for symbol in message:
        if symbol.isalpha():
            num = ord(symbol)
            num += key
            if num > ord('z'):
                num -= 26
            elif num < ord('a'):
                num += 26
            transled += chr(num)
        else:
            transled += symbol
    return transled

brute(get_message())

reference


PREV     NEXT