[Cryptography·Miracl Function Library Application] Start the first test program

After compiling the static resource library miracl.lib, you can start using our miracl library. When packaging miracl.lib, a test code was given. Let’s start a simple study.
Miracl is based on the standard C language, so when it is used, C language is also used for development, then the compilation environment can be placed in the C language environment through extern "c". Add the following code at the beginning of the file.

extern "C"
{
    
    
	#include "miracl.h"
	#include "mirdef.h"
}
#pragma comment(lib,"miracl.lib")

Take the first function absol as an example. The function of absol function is to find the absolute value. The complete code in the main function is

extern "C"
{
    
    
	#include "miracl.h"
	#include "mirdef.h"
}
#pragma comment(lib,"miracl.lib")

int main()
{
    
    
	big x, y;
	
	miracl *mip = mirsys(500, 10); //初始化miracl系统,初始化一个500位10进制的大数系统

	x = mirvar(-100);//初始化必要步骤
	y = mirvar(0);

	absol(x, y);

	mip->IOBASE = 16;//将数值转换为16进制

	cotnum(x, stdout); //输出
	cotnum(y, stdout); 
	   
	mirkill(x);          //释放大数变量
	mirkill(y);

	return 0;
}

A few notes about this code:

  1. The first is to include the header file, which should be placed in the C language environment, so the inclusion of the header file is in extern "C".
  2. The definition of the variable is the same as that of the standard C language, and can be placed at the beginning of the function. Then it is to initialize a miracl, which is to define a mip pointer. This is essential, and the definition should be completed before calling the miracl library, so it can be placed after the variable definition.
  3. The function mirval is used to initialize integers, which can be very large or very small. The variables of the big type defined earlier need to be initialized.
  4. The function absol is an absolute value function. It has two parameters. The first parameter is the input integer, and the second parameter is the absolute value of the first parameter. The function absol takes the absolute value of the first parameter to the first parameter. Two parameters.
  5. mip->IOBAES=16 means that the result is converted to a hexadecimal number, and the final output result is indeed a hexadecimal number.
  6. The function cotnum is an output function, which prints out the dynamic results, and the results seen in the black control panel are printed by this function.
  7. The function mirkill represents the release of the requested large data memory, that is, the memory of the defined variables of the big type.

Guess you like

Origin blog.csdn.net/m0_50984266/article/details/108711314