Difference between revisions of "Practice Everyday"

Jump to navigation Jump to search
949 bytes added ,  11:02, 26 May 2023
Line 6: Line 6:


*自己给自己写了一篇日记,研究研究能不能私密发布,公开发布不好。
*自己给自己写了一篇日记,研究研究能不能私密发布,公开发布不好。
--- Joe version ---
'''真正的私密'''
<syntaxhighlight lang="c" line style="border: 1px dashed red;">
#include <stdio.h>
#include <string.h>
// encrypt
void encrypt(char *str, int key)
{
    int len = strlen(str);
    for (int i = 0; i < len; i++)
    {
        str[i] += key;
    }
}
// decrypt
void decrypt(char *str, int key)
{
    int len = strlen(str);
    for (int i = 0; i < len; i++)
    {
        str[i] -= key;
    }
}
int main()
{
    char str[100];
    int key;
    // what do you want encrypt
    printf("请输入要加密的字符串:");
    fgets(str, sizeof(str), stdin);
    printf("请输入密钥:"); //Remeber it, it's important
    scanf("%d", &key);
    // encrypt what do you input
    encrypt(str, key);
    printf("加密后的字符串为:%s\n", str);
    // decrypt what do you encrypted
    decrypt(str, key);
    printf("解密后的字符串为:%s\n", str);
    return 0;
}
</syntaxhighlight>


== Day 92 ==
== Day 92 ==

Navigation menu