惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 心有

go语言最好的帮助在哪里? go语言的init函数 我的go语言上机测试代码 解决golang.org不能访问的问题 win7下安装32位GoSublime Package oracle和sybase的帮助文档 用bat文件设置程序启动环境 go语言 windows 32位编译环境搭建 Go没有枚举类型(enums),用const常量的iota替代 oracle数据库性能优化 - 降低IO c#长字符串显示省略号 - 心有 - 博客园 C#的timer类问题~! 计划任务工具 cron 的配置和说明 TRACERT命令及用法 linux下挂载windows的共享文件目录ftp文件夹到/root/wind目录 Linux 用户(user)和用户组(group)管理概述 Linux用户和用户组的管理概述 用NetTerm连接虚拟机的telnet服务,打造轻松自如的虚拟机实验环境 请高人指点下,手机震动时从平台上掉入水中,是用户使用不当还是手机设计缺陷,维修费用由谁承担?
c语言中的大数运算模块
心有 · 2012-05-13 · via 博客园 - 心有

  随着计算机系统的快速发展,经常需要对海量数据和信息做处理,在处理这些数据时经常会遇到很大的数字,无法用int或者long等类型来存储,经常看到有人自己在写或者讨论大数相关的问题,本文描述从开源库polarssl中提取的大数bignum模块,独立出来集成到应用程序中的方法,该模块支持的大数位数不限制。

  摘取出来的模块仅仅包含:bignum.c、bignum.h、bn_mul.h三个文件,简单易用。

  相关代码和测试代码如下:

 /Files/youyou/bignum.rar

 1 #include <string.h>
 2 #include <stdio.h>
 3 
 4 #include "bignum.h"
 5 
 6 void test_add_mul()
 7 {
 8 /*
 9 //test result:
10     A = 123456789012345678901234567890
11     B = 123456789012345678901234567890
12     X = A + B
13     X = 246913578024691357802469135780
14 
15     A = 123456789012345678901234567890
16     B = 123456789012345678901234567890
17     X = A * B
18     X = 15241578753238836750495351562536198787501905199875019052100
19   
20     press any key to contiue ...
21 */
22     int ret, temp;
23     mpi A, B, X;
24     size_t n;
25     char a[ 2 * POLARSSL_MPI_MAX_SIZE + 2 ];
26     char b[ 2 * POLARSSL_MPI_MAX_SIZE + 2 ];
27     char x[ 2 * POLARSSL_MPI_MAX_SIZE + 2 ];
28 
29     n = sizeof(a);
30     temp = n - 2;    
31         
32     mpi_init( &A ); mpi_init( &B ); mpi_init( &X );
33     
34     MPI_CHK( mpi_read_string( &A, 10,
35         "123456789012345678901234567890") );
36     
37     MPI_CHK( mpi_read_string( &B, 10,
38         "123456789012345678901234567890") );
39     
40     MPI_CHK( mpi_add_mpi( &X, &A, &B ) );
41 
42     memset( a, 0sizeof(a) );
43     memset( b, 0sizeof(b) );
44     memset( x, 0sizeof(x) );
45     n = temp;
46     MPI_CHK( mpi_write_string( &A, 10, a, (size_t *) &n ) );    
47     n = temp;
48     MPI_CHK( mpi_write_string( &B, 10, b, (size_t *) &n ) );    
49     n = temp;
50     MPI_CHK( mpi_write_string( &X, 10, x, (size_t *) &n ) );    
51     printf("A = %s\n", a);
52     printf("B = %s\n", b);
53     printf("X = A + B\n");
54     printf("X = %s\n", x);
55     printf("\n");
56 
57     MPI_CHK( mpi_mul_mpi( &X, &A, &B ) );
58     
59     memset( a, 0sizeof(a) );
60     memset( b, 0sizeof(b) );
61     memset( x, 0sizeof(x) );
62     n = temp;
63     MPI_CHK( mpi_write_string( &A, 10, a, (size_t *) &n ) );    
64     n = temp;
65     MPI_CHK( mpi_write_string( &B, 10, b, (size_t *) &n ) );    
66     n = temp;
67     MPI_CHK( mpi_write_string( &X, 10, x, (size_t *) &n ) );    
68     printf("A = %s\n", a);
69     printf("B = %s\n", b);
70     printf("X = A * B\n");
71     printf("X = %s\n", x);
72     printf("\n");
73         
74 cleanup:
75     
76     mpi_free( &A ); mpi_free( &B ); mpi_free( &X );
77 }
78 
79 void my_pause()
80 {
81     printf("press any key to contiue ...");
82     getchar();
83 }
84 
85 int main( int argc, char *argv[] )
86 {
87 
88     test_add_mul();
89 
90     my_pause();
91 
92     return 0;

93 }