testgmp.cpp

来自「伯克利做的SFTP安全文件传输协议」· C++ 代码 · 共 54 行

CPP
54
字号
// testgmp.cpp// stand-alone test of GMP; not very thorough, as it is really// intended just to verify GMP is installed right.  more extensive// tests are in selgamal.cpp and sdsa.cpp#include "gmp.h"     // GMP functions#include <stdio.h>   // printfint main(){  printf("beginning of main\n");  mpz_t x, y, z, zero;  mpz_init(x);  mpz_init(y);  mpz_init(z);  mpz_init(zero);  mpz_add_ui(x, zero, 30);  if (mpz_get_ui(x) != 30) {    printf("mpz_add_ui or mpz_get_ui doesn't work\n");    return 4;  }  mpz_add_ui(y, zero, 7);  mpz_add(z, x, y);  if (mpz_get_ui(z) != 37) {    printf("mpz_add doesn't work\n");    return 4;  }  if (mpz_invert(x, y, z)==0) {     // y = inverse of 7 (mod 37), should be 16    printf("mpz_invert doesn't work (claims no inverse exists)\n");    return 4;  }  unsigned ux = mpz_get_ui(x);  printf("inverse of 7 (mod 37) is %u\n", ux);  if (ux != 16) {    printf("mpz_invert doesn't work\n");    return 4;  }  mpz_clear(x);  mpz_clear(y);  mpz_clear(z);  mpz_clear(zero);  printf("end of main\n");  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?