Encrypted Password UVALive - 6320 字符串

题目链接:

Encrypted Password

UVALive - 6320


                                                                                                   

tho:      n 方会超时, 所以就转换成 n*26 的算法



#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define inf 0x3f3f3f
#define ms(x) memset(x,0,sizeof(x))
using namespace std;
int main()
{
    int T;
    char s[100123];
    char t[100123];
    int book[30];
    int vis[30];
    while(cin>>T)
    {
        while(T--)
        {
            ms(book);
            ms(vis);
            scanf("%s",s);
            scanf("%s",t);
            int ls = strlen(s);
            int lt = strlen(t);
            for(int i=0;i<lt;i++)
            {
                vis[s[i]-'a']++;          //生成串
                book[t[i]-'a']++;         //原串
            }
            int f;
            for(int i=0;i+lt<=ls;i++)
            {
                f=1;
                for(int j=0;j<27;j++)
                {
                    if(book[j]!=vis[j])
                    {
                        f=0;break;
                    }
                }
                vis[s[i]-'a']--;
                vis[s[i+lt]-'a']++;
                if(f) break;
            }
            if(f) printf("YES\n");
            else printf("NO\n");
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在RAM芯片上实现RSA加密的主要难点在于内存空间限制,因为RSA加密需要使用到大量的内存空间。对于RSA-512算法,需要使用64字节的公钥进行加密。因此,需要使用适当的方法来处理内存空间限制问题。 以下是一个C语言实现的示例代码,用于在RAM芯片上对字符串进行RSA-512公钥加密: ```c #include <stdio.h> #include <string.h> #include <openssl/rsa.h> #include <openssl/pem.h> // RSA公钥 const unsigned char rsa_public_key[] = { 0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xB3, 0xD2, 0x64, 0xCB, 0x5B, 0x16, 0x9A, 0x6A, 0xD5, 0x05, 0x2C, 0x6B, 0x41, 0x65, 0x5E, 0x13, 0xC3, 0x6A, 0x0C, 0x2F, 0x90, 0xF5, 0x2C, 0x5A, 0x1B, 0x3D, 0x8C, 0xB8, 0x47, 0x96, 0x40, 0x76, 0x73, 0x49, 0x30, 0x68, 0x2A, 0x41, 0x5C, 0x9D, 0x1F, 0x0E, 0x47, 0x0A, 0x3C, 0x25, 0x0C, 0xE8, 0x3D, 0x77, 0x64, 0x0A, 0x4F, 0x3C, 0x01, 0x46, 0x1F, 0x5F, 0x29, 0x02, 0x03, 0x01, 0x00, 0x01 }; // RSA加密函数 int rsa_encrypt(const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen) { int ret = 0; RSA *rsa = NULL; BIO *keybio = NULL; // 解析公钥 keybio = BIO_new_mem_buf((void *)rsa_public_key, sizeof(rsa_public_key)); if (keybio == NULL) { return -1; } rsa = PEM_read_bio_RSA_PUBKEY(keybio, NULL, NULL, NULL); if (rsa == NULL) { BIO_free(keybio); return -1; } // 进行加密 *olen = RSA_public_encrypt(ilen, input, output, rsa, RSA_PKCS1_PADDING); // 释放资源 RSA_free(rsa); BIO_free(keybio); return 0; } // 主函数 int main(void) { const char *input_str = "Hello, world!"; unsigned char input[64] = {0}; unsigned char encrypted[64] = {0}; size_t ilen = 0, olen = 0; // 将输入字符串拷贝到输入缓冲区 ilen = strlen(input_str); memcpy(input, input_str, ilen); // 进行RSA加密 if (rsa_encrypt(input, ilen, encrypted, &olen) != 0) { printf("RSA encrypt error!\n"); return -1; } // 输出加密结果 printf("Encrypted message: "); for (size_t i = 0; i < olen; i++) { printf("%02X ", encrypted[i]); } printf("\n"); return 0; } ``` 在上述代码中,公钥使用的是一个常量数组`rsa_public_key`,大小为89字节。在进行RSA加密时,输入数据被拷贝到一个大小为64字节的输入缓冲区`input`中,然后进行加密操作。输出数据被存储到一个大小为64字节的输出缓冲区`encrypted`中,输出数据长度为实际加密后的字节数`olen`。 需要注意的是,在进行RSA加密时,需要使用到适当的填充方式,例如RSA_PKCS1_PADDING。此外,为了避免内存溢出的问题,需要对输入和输出缓冲区进行合适的大小分配。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值