吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 995|回复: 0
收起左侧

[CTF] 关于ROT13(等凯撒密码)和栅栏密码

[复制链接]
zhefox 发表于 2021-8-7 15:30
本帖最后由 zhefox 于 2021-8-10 00:13 编辑

ROT13
ROT13是凯撒密码Caesar中特殊的一个偏移加密名称
对应的是偏移量为13一般来说,ROT13加密两次就自行解密了,它的作用基本仅限于让机器无法识别。
Caesar(凯撒密码)
加密时会将明文中的 每个字母 都按照其在字母表中的顺序向后(或向前)移动固定数目(循环移动)作为密文,即当一个字符ascll码为65(A),当我的偏移量设置为右偏移5,则得到的密文为70(F)
//ASCLL图片上传有点问题,,这里就不放了
blog.restro.cn/index.php/2021/08/07/97/                                   可以看这个文章



加解密脚本
[Python] 纯文本查看 复制代码
def casearDecrypt(ciphertext, source_char, destination_char, list_all):
    if list_all == True:
        for offset in range(1, 27):
            convertChar(offset)
    else:
        offset = ord(destination_char) - ord(source_char)
        convertChar(offset)


def convertChar(offset):
    chars = "abcdefghijklmnopqrstuvwxyz"
    for char in ciphertext:

        is_upper_flag = 0
        if char.isupper():
            char = char.lower()
            is_upper_flag = 1

        if char not in chars:
            outputChar(is_upper_flag, char)
            continue

        tempchar_ascii = ord(char) + offset
        tempchar = chr(tempchar_ascii)
        if tempchar not in chars:
            if offset < 0:
                tempchar_ascii += len(chars)
            else:
                tempchar_ascii -= len(chars)
        tempchar = chr(tempchar_ascii)
        outputChar(is_upper_flag, tempchar)
    print("")


def outputChar(is_upper_flag, char):
    if is_upper_flag == 1:
        print(char.upper(), end="")
    else:
        print(char, end="")


ciphertext = input("Please input ciphertext:\n")
while True:
    operation = input("List all results?y/n:")
    if operation == 'y' or operation == 'Y':
        casearDecrypt(ciphertext, '', '', True)
        break
    elif operation == 'n' or operation == 'N':
        des_char = input("Please input destination_char:\n")
        sors_char = input("Please input source_char:\n")
        casearDecrypt(ciphertext, sors_char, des_char, False)
        break
    else:
        print("Input error! Please input y/n:")



凯撒密码解密脚本(python)_Squeen_的专栏-CSDN博客_凯撒密码脚本

拓展
ROT5 是 rotate by 5 places 的简写,意思是旋转5个位置,其它皆同。下面分别说说它们的编码方式:
ROT5:只对数字进行编码,用当前数字往前数的第5个数字替换当前数字,例如当前为0,编码后变成5,当前为1,编码后变成6,以此类推顺序循环。
ROT13:只对字母进行编码,用当前字母往前数的第13个字母替换当前字母,例如当前为A,编码后变成N,当前为B,编码后变成O,以此类推顺序循环。
ROT18:这是一个异类,本来没有,它是将ROT5和ROT13组合在一起,为了好称呼,将其命名为ROT18。
ROT47:对数字、字母、常用符号进行编码,按照它们的ASCII值进行位置替换,用当前字符ASCII值往前数的第47位对应字符替换当前字符,例如当前为小写字母z,编码后变成大写字母K,当前为数字0,编码后变成符号_。用于ROT47编码的字符其ASCII值范围是33-126,具体可参考ASCII编码。
此类编码具有可逆性,可以自我解密,主要用于应对快速浏览,或者是机器的读取,而不让其理解其意。



栅栏密码
原理,类似于当原文为123456
加密2栏过程为拆为123   和  456 然后穿插进去 组成142536
解密则想办法逆向

解密脚本
[Python] 纯文本查看 复制代码
#coding:utf-8
mima=input("请输入密文")
lanshu=int(input("请输入栏数"))
lenth=len(mima)
zhalan = []
for i in range(lanshu,lenth):
    if i%lanshu==0:
        zhalan.append(i)
pass
for a in zhalan:
    result=[]
    for b in range(a):
        for c in range(b,lenth,a):
            result.append(mima[c])

    print("".join(result))

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
vethenc + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-16 22:13

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表