-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassicalCipher.cpp
More file actions
57 lines (57 loc) · 849 Bytes
/
ClassicalCipher.cpp
File metadata and controls
57 lines (57 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 古典密码
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char a[20] = "RZfhrJhr##6opwG";
int main()
{
char s[20];
char b[20];
int n,i,k,key,j,z;
printf("Hello,this is a easyre\n");
printf("please input the flag:");
// 替换为安全的fgets输入
if (!fgets(s, sizeof(s), stdin)) {
printf("输入失败\n");
return 1;
}
n = strlen(s);
if(n != 15)
{
printf("error!");
exit(0);
}
key = 3;
for(i = 0;s[i]!='\0';i++)
{
s[i] += 3;
}
for(i = 0;s[i] !='\0';i++)
{
k = (i+key)%n;
b[k] = s[i];
}
b[i]='\0';
strcpy(s,b);
k = 0;
z = n/3;
for(i = 0;s[i] != '\0';i+=3)
{
k = i/3;
for(j = 0;j<3;j++)
{
b[k+j*z]=s[i+j];
}
}
b[i] = '\0';
strcpy(s,b);
if(strcmp(s,a) == 0)
{
printf("Congratulations!!!!!!!!!!!!!!!!!!\n");
}
else
{
printf("Try again\n");
}
return 0;
}