BUU_RE第一页

[SUCTF2019]SignIn

就输入字符串转换为十六进制(映射法)

每个输入字符要转换为两位十六进制数

  • a1[index] >> 4 将字符右移 4 位,相当于获取高四位的值,然后在 a0123456789abcd 中查找对应的十六进制表示,将结果存储到地址 a2 + i 中。
  • a1[index] & 0xF 获取字符的低四位的值,然后同样在 a0123456789abcd 中查找对应的十六进制表示,将结果存储到地址 a2 + i + 1 中。
table='0123456789abcdef'
str='hello,Tom!'
index=0
length=len(str)
a2=[0]*length*2
for i in range(0,length*2,2):
    a2[i]=table[ord(str[index])>>4]
    a2[i+1]=table[ord(str[index])&0xf]
    index+=1
start=''.join(a2)
print(start)
data=int(start,16)
print(hex(data+1))

 

output = "73756374667b50776e5f405f68756e647265645f79656172737d"
flag = [''] * (len(output) // 2)
mapTable = "30 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66".split(' ')
mapTable = [chr(int(i, 16)) for i in mapTable]

for i in range(0, len(output), 2):
	high4Bit = mapTable.index(output[i])
	low4Bit  = mapTable.index(output[i+1])
	curByte  = high4Bit << 4 | low4Bit
	flag[i//2] = chr(curByte)
print(''.join(flag))

然后就是几个高精度函数变量运算

__gmpz_init_set_str(v5, "65537", 10LL);

int v5=65537

 void mpz_powm (mpz_t rop, const mpz_t base, const mpz_t exp, const mpz_t mod)

__gmpz_powm((__int64)v6, (__int64)v6, (__int64)v5, (__int64)v4);// v6=v6^v5%v4 

计算 base 的 exp 次方,并对 mod 取模,最后将结果写入 rop  ==>RSA加密

RSA加密算法:

图中的C是密文,M是明文,E是公钥(E和 φ(N)互为质数),N是公共模数(质数 P 、Q相乘得到N),MOD就是模运算
解密算法:

图中的C是密文,M是明文,D是私钥(私钥由这个公式计算得出E * D % φ(N) = 1),N是公共模数(质数 P 、Q相乘得到N),MOD就是模运算,φ(N)是欧拉函数(由这个公式计算得出φ(N) = (P-1)(Q-1))。

本题知道

1 C = 0xad939ff59f6e70bcbfad406f2494993757eee98b91bc244184a377520d06fc35
2 N = 103461035900816914121390101299049044413950405173712170434161686539878160984549
3 E = 65537
import binascii
import gmpy2
flag=''
c=0xad939ff59f6e70bcbfad406f2494993757eee98b91bc244184a377520d06fc35
e=65537
p=282164587459512124844245113950593348271
q=366669102002966856876605669837014229419
n=103461035900816914121390101299049044413950405173712170434161686539878160984549
d=int (gmpy2. invert (e, (q-1)*(p-1)))
m=gmpy2. powmod (c, d, n)
h=hex(m) [2:]
flag += binascii. a2b_hex(h). decode(encoding=' utf-8', errors= 'ignore')
print (flag)

https://www.cnblogs.com/sk2rw/p/13772056.html

大数处理

较小可以用 stringstream

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>

int main() {
    int v5 = 65537;
    std::string v4 = "103461035900816914121390101299049044413950405173712170434161686539878160984549";
    std::string v6 = "ad939ff59f6e70bcbfad406f2494993757eee98b91bc244184a377520d06fc35";
    long long flag;
    int count = 0;

    // Use stringstream to convert hex string to unsigned long long
    unsigned long long data;
    std::stringstream ss;
    ss << std::hex << v6;
    ss >> data;

    std::cout << "Converted value: " << data << std::endl;

    return 0;
}

超大整数

#include <iostream>
#include <string>
#include <gmp.h>

int main() {
    std::string v6 = "ad939ff59f6e70bcbfad406f2494993757eee98b91bc244184a377520d06fc35";

    // Initialize a GMP integer
    mpz_t data;
    mpz_init(data);

    // Convert hex string to GMP integer
    mpz_set_str(data, v6.c_str(), 16);

    // Print the GMP integer
    std::cout << "Converted value: ";
    mpz_out_str(stdout, 10, data);
    std::cout << std::endl;

    // Clear the GMP integer
    mpz_clear(data);

    return 0;
}

[MRCTF2020]hello_world_go

go 语言的题,听说很难,没怎么遇到

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值