判断对称数:int JudgeNumberSymmetry(unsigned long ulNumber)

 判断一个正整数是否为对称数(对称数即左右对称的数字,如3、22、121、1331、34543),是返回1,不是返回0。
 (用ulNumber的最高位做ulResult的最低位,用ulNumber的最低位做ulResult的最高位,位序倒过来,判断是否为对称数)
#include<stdio.h>
#include<stdlib.h>

int JudgeNumberSymmetry(unsigned long ulNumber)   
{

unsigned long ulTemp=ulNumber;                        

unsigned long ulResult=0;
int iMod=0;
while(ulTemp)
{
iMod=ulTemp%10;
ulResult=ulResult*10+iMod;
ulTemp=ulTemp/10;
}
if(ulResult==ulNumber)
return 1;
else
return 0;
}

int main()
{
int a;
unsigned int num;
printf("input the number:");
scanf("%ld",&num);
a=JudgeNumberSymmetry(num);
if(a==1)
printf("the number %ld is Symmetry!\n",num);
else
printf("the number %ld is not Symmetry!\n",num);
system("pause");
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
RSA是一种非对称加密算法,可以用于字签名。下面是一个使用C++实现RSA字签名的例子: ```cpp #include <iostream> #include <string> #include <openssl/rsa.h> #include <openssl/pem.h> using namespace std; int main() { // 生成RSA密钥对 RSA *keypair = RSA_generate_key(2048, RSA_F4, NULL, NULL); if (keypair == NULL) { cout << "Failed to generate RSA key pair." << endl; return 1; } // 获取私钥和公钥 BIO *pri = BIO_new(BIO_s_mem()); BIO *pub = BIO_new(BIO_s_mem()); PEM_write_bio_RSAPrivateKey(pri, keypair, NULL, NULL, 0, NULL, NULL); PEM_write_bio_RSAPublicKey(pub, keypair); // 从BIO中读取私钥和公钥 char *pri_key = NULL; char *pub_key = NULL; long pri_len = BIO_get_mem_data(pri, &pri_key); long pub_len = BIO_get_mem_data(pub, &pub_key); // 签名 string message = "Hello, world!"; unsigned char *sig = new unsigned char[RSA_size(keypair)]; unsigned int sig_len; RSA_sign(NID_sha256, (const unsigned char *)message.c_str(), message.length(), sig, &sig_len, keypair); // 验证签名 int result = RSA_verify(NID_sha256, (const unsigned char *)message.c_str(), message.length(), sig, sig_len, keypair); if (result == 1) { cout << "Signature verified." << endl; } else { cout << "Signature verification failed." << endl; } // 输出私钥和公钥 cout << "Private key:" << endl << string(pri_key, pri_len) << endl; cout << "Public key:" << endl << string(pub_key, pub_len) << endl; // 释放资源 RSA_free(keypair); BIO_free_all(pri); BIO_free_all(pub); delete[] sig; return 0; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值