Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
Hepper123 committed Mar 10, 2021
1 parent 3cc3560 commit 869e547
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions level1/p07_encrypt_decrypt/encrypt_decrypt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <stdio.h>
#include <string.h>
#include <iostream>

void encrypt(char* source, char* encrypted)
{
while (*source != '\0')
{
*encrypted = 158 - *source;
source++;
encrypted++;
}
}

void decrypt(char* encrypted, char* source)
{
while (*encrypted != '\0')
{
*source = 158 - *encrypted;
source++;
encrypted++;
}
}

int main()
{
printf("请输入需要加密字符串的长度:");
int n = 0;
std::cin >> n;
char* a = new char[n + 1]();
char* b = new char[n + 1]();
scanf("%s", a);
encrypt(a, b);
printf("加密后的字符串为:");
printf("%s\n", b);
printf("请输入需要解密的字符串的长度:");
int s = 0;
scanf("%d", &s);
char* c = new char[n + 1]();
char* d = new char[n + 1]();
printf("需要解密的字符串为:");
scanf("%s", c);
decrypt(c, d);
printf("解密后的字符串为:");
printf("%s", d);
}

0 comments on commit 869e547

Please sign in to comment.