常见加密算法解密脚本

2023-12-13 04:43:50

TEA

#include<stdio.h>
#define  u_int unsigned int
int main()
{
	u_int enc[] = { 4006073346, 2582197823, 2235293281, 558171287,
				2425328816, 1715140098, 986348143, 1948615354 };
	u_int k[] = { 255, 187, 51, 68 };
	for (int i = 0; i < 8; i += 2)
	{
		u_int delta = 195935983;
		u_int s1 = delta * 32;
		for (int j = 0; j < 32; j++)
		{
			enc[i + 1] -= (enc[i] << 4 ^ enc[i] >> 7) + enc[i] ^ s1 + k[s1 >> 9 & 3];
			s1 -= delta;
			enc[i] -= (enc[i + 1] << 4 ^ enc[i + 1] >> 7) + enc[i + 1] ^ s1 + k[s1 & 3];
		}
	}
	char flag[32] = { 0 };
	for (int i = 0; i < 8; i++)
	{
		flag[4 * i] = enc[i] >> 24;
		flag[4 * i + 1] = (enc[i] >> 16) ^ 0xFF000000;
		flag[4 * i + 2] = (enc[i] >> 8) ^ 0xFF000000;
		flag[4 * i + 3] = enc[i] ^ 0xFF000000;
	}
	for (int i = 0; i < 32; i++)
	{
		printf("%c", flag[i]);
	}
}

RC4解密脚本

def rc4_decrypt(ciphertext, key):
    S = list(range(256))
    j = 0
    res = []

    # KSA (Key Scheduling Algorithm)
    for i in range(256):
        j = (j + S[i] + key[i % len(key)]) % 256
        S[i], S[j] = S[j], S[i]

    # PRGA (Pseudo Random Generation Algorithm)
    i = j = 0
    for byte in ciphertext:
        i = (i + 1) % 256
        j = (j + S[i]) % 256
        S[i], S[j] = S[j], S[i]
        k = S[(S[i] + S[j]) % 256]
        res.append(byte ^ k)

    return bytes(res)

# 示例使用
ciphertext = [0x1B, 0x9B, 0xFB, 0x19, 0x06, 0x6A, 0xB5, 0x3B, 0x7C, 0xBA,
  0x03, 0xF3, 0x91, 0xB8, 0xB6, 0x3D, 0x8A, 0xC1, 0x48, 0x2E,
  0x50, 0x11, 0xE7, 0xC7, 0x4F, 0xB1, 0x27, 0xCF, 0xF3, 0xAE,
  0x03, 0x09, 0xB2, 0x08, 0xFB, 0xDC, 0x22]  # 替换为你的密文
key = b'moectf2023'

plaintext = rc4_decrypt(ciphertext, key)
print("解密结果:", plaintext.decode())

RSA

在线进制转换工具

进制转换 - 在线工具

分离工具factordb.com

解密脚本

import gmpy2
import binascii

p = 282164587459512124844245113950593348271
q = 366669102002966856876605669837014229419
e = 65537
c = 0xad939ff59f6e70bcbfad406f2494993757eee98b91bc244184a377520d06fc35
n = p * q
d = gmpy2.invert(e, (p-1) * (q-1))
m = gmpy2.powmod(c, d, n)

print(binascii.unhexlify(hex(m)[2:]).decode(encoding="utf-8"))

解密文件脚本

import gmpy2
import rsa
num = "C0332C5C64AE47182F6C1C876D42336910545A58F7EEFEFC0BCAAF5AF341CCDD"
N = int(num,16)
E = 65537
p = 285960468890451637935629440372639283459
q = 304008741604601924494328155975272418463
D = int(gmpy2.invert(E,(p-1)*(q-1)))
privtekey = rsa.PrivateKey(N, E, D, p, q)
with open("C:\\Users\\DELL\\Desktop\\output\\flag.enc", "rb+") as file:
    text = file.read()
message = rsa.decrypt(text,privtekey)
print(message)

SM解密网站

在线SM4国密加密/解密—LZL在线工具

sha爆破脚本

import hashlib
hash="6e2b55c78937d63490b4b26ab3ac3cb54df4c5ca7d60012c13d2d1234a732b74"
for i in range(90000000):
    pwd1=hex(i)
    pwd1=pwd1[2:]
    h1=hashlib.sha256(pwd1.encode('utf-8')).hexdigest()
    #print(h1)
    if h1==hash:
        print(hex(i))
        break

MD5爆破脚本

import itertools
import string
import hashlib

def md5crash(sha256enc):
    code = ''
    strlist = itertools.product(string.ascii_letters + string.digits, repeat=4)

    for i in strlist:
        code = i[0] + i[1] + i[2] + i[3]
        encinfo = hashlib.md5(code.encode()).hexdigest()
        if encinfo == sha256enc:
            return code

flag = md5crash("ff6e2fd78aca4736037258f0ede4ecf0")
print(flag)

文章来源:https://blog.csdn.net/m0_73644864/article/details/134957995
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。