c - 打印存储为 unsigned long long 数组的大整数
问题描述
我正在审查一个大学项目的应用程序的安全性,该应用程序使用 RSA 加密文件,特别是它使用这个库:https ://github.com/ilansmith/rsa (不要使用它,它有严重的漏洞) .
(如果你想看一下,这些数字之间的大部分操作都是在rsa_num.c
文件中实现的。)
此工具使用 的数组来存储 RSA (和)unsigned long long
所需的大数:n
e
d
typedef struct {
u64 arr[17]; //u64 is defined as unsigned long long
int top; //points to the last occupied slot of the array
} u1024_t;
问题是我不明白数字是如何以这种格式存储的。我需要的是能够以某种方式打印实数,或者至少是一种从数组组件中恢复数字的方式。
我尝试将它们像字符串一样连接起来,但这似乎不正确。
感谢任何能够提供帮助的人!
解决方案
谢谢@Matthieu!你的评论奏效了。由于字节顺序,我需要以unsigned long long
相反的顺序连接 s 并反转它们的字节。
按照他的解决方案,我实现了这个功能,效果很好:
void print_u1024(u1024_t number) {
int size = (number.top + 1) * sizeof(u64);
for (int i = size-1; i >= 0; i--) {
printf("%02x", ((unsigned char*)number.arr)[i]);
}
printf("\n");
}
请注意,此解决方案可能仅适用于 little-endian 系统(大多数 PC)。
推荐阅读
- google-bigquery - 手动运行时 Google BigQuery 调度查询错误
- html - 检查是否在角度指令中检查了另一个元素
- javascript - 如何在 google Drive API 的文件夹之间移动文件?
- c# - 如何使用 LeanTouch 免费资产处理 Unity3D 上的触摸选择?
- java - Java 月枚举
- angular - 加载组件后滚动到 Material Accordion 中的特定扩展面板
- android - 如何使应用程序范围内的 android 应用程序数据可用?
- jquery - 我正在尝试使用 dynatable 显示本地 json 文件中的数据,但我在表中的值中未定义?
- python - 为什么python PIL不能在一个程序中显示两个图像
- node.js - NodeJs - 导入的变量未定义