列一个表,a=0,b=2,c=2,.... =26,(这里是有 的哦),再循环a=27....以此类推,最多能到123个(27*4+15)。
加密后的文件是:ifpmluglesecdlqp_rclfrseljpkq
解密后的文件是:flag_is_every_haxor_love_math
下面给出几个解密脚本,仅供参考:
#include <iostream>
int main() {
std::string map{ "abcdefghijklmnopqrstuvwxyz_" };
std::string pass{ "ifpmluglesecdlqp_rclfrseljpkq" };
for (auto i : pass)
{
int temp = map.find(i) - 15;//根据题意 -15
if (temp < 0)
temp += 27;//修正位置
while (temp % 4)//根据题意 temp 必须是 4 的倍数
temp += 27;//修正数据,直到可以被 4 整除
std::cout << map[temp / 4];
}
}
#include <iostream>
int main()
{
const int MAX_Table = 27;
char szTable[MAX_Table] = { 0 };
for (int index = 0;index < MAX_Table - 1;++index)
{
szTable[index] = 'a' + index;
}
szTable[MAX_Table - 1] = '_';
char szMsg[] = "ifpmluglesecdlqp_rclfrseljpkq";
int len = sizeof(szMsg) - 1;
for (int index = 0;index < len;++index)
{
for (int tIndex = 0;tIndex < MAX_Table;++tIndex)
{
if (szTable[(tIndex * 4 + 15) % MAX_Table] == szMsg[index])
{
szMsg[index] = szTable[tIndex];
break;
}
}
}
std::cout << "flag:" << szMsg << std::endl;
system("pause");
return 0;
}
# coding:utf8
original = 'abcdefghijklmnopqrstuvwxyz_'
encrypted = 'ifpmluglesecdlqp_rclfrseljpkq'
def egcd(a, b):
if a == 0:
return (b, 0, 1)
else:
g, y, x = egcd(b % a, a)
return (g, x - (b // a) * y, y)
def modinv(a, m):
g, x, y = egcd(a, m)
if g != 1:
raise Exception('modular inverse does not exist')
else:
return x % m
def main():
result = ''
# 求4的逆元
a = modinv(4, 27)
for e in encrypted:
result += original[((original.index(e)-15) * a) % 27]
print(result)
if __name__ == '__main__':
main()
#! /usr/bin/python3
if __name__ == '__main__':
alphabet = "abcdefghijklmnopqrstuvwxyz_"
counts = len(alphabet)
ciphers = {}
for idx in range(0, counts):
pos = (idx * 4 + 15) % counts
ciphers[alphabet[pos]] = idx
r = ""
for s in "ifpmluglesecdlqp_rclfrseljpkq":
pos = ciphers[s]
r += alphabet[pos]
print ( r )
|