当前位置:网站首页>Introduction to cyberspace and implementation of cryptography operation
Introduction to cyberspace and implementation of cryptography operation
2022-04-21 08:06:00 【After the rain &】
It was written a long time ago , But my code hasn't improved much
Caesar encryption
#include<stdio.h>
#include<string.h>
void m();// menu
void getinput(char input[]);// Get string
void encrypt(char eninput[],char input[],char map[]);// encryption
void decode(char deinput[],char input[],char map[]);// Decrypt
int main()
{ int ch = 1;
char input[1000];
char eninput[1000];
char deinput[1000];
char map[26];
int i = 0;
for(i = 0;i<26;i++)
{
map[i]='a'+i;
}
while(ch)
{
m();
scanf("%d",&ch);
if(ch==1)
{
getinput(input);
}
else if(ch==2)
{
encrypt(eninput,input,map);
}
else if(ch==3)
{
decode( deinput, input, map);
}
else break;
}
return 0;
}
void m()
{
printf("----- Caesar encryption ---------\n");
printf("-----1. Input string -----\n");
printf("-----2. encryption -----------\n");
printf("-----3. Decrypt -----------\n");
printf("-----4. Exit procedure -------\n");
printf(" Please enter :");
}
void getinput(char input[])
{
printf(" Letters are encrypted and decrypted in lowercase \n");
getchar();
gets(input);
}
void encrypt(char eninput[],char input[] ,char map[])
{
printf(" Please enter the offset key(1,25):\n");
int key;
scanf("%d",&key);
int i = 0,j = 0;
for( i = 0;i<strlen(input);i++)
{
for(j = 0;j<26;j++)
{
if((input[i]==map[j])||input[i]==(map[j]-32))
{
eninput[i]=((map[j]-'a')+key)%26+'a';// encryption
}
}
}
eninput[i]='\0';
input[i]='\0';
printf(" Before encryption :%s\n",input);
printf(" After encryption :%s\n",eninput);
}
void decode(char deinput[],char input[],char map[])
{
printf(" Please enter the offset key(1,25):\n");
int key;
scanf("%d",&key);
int i = 0,j = 0;
for( i = 0;i<strlen(input);i++)
{
for(j = 0;j<26;j++)
{
if(input[i]==map[j]||input[i]==map[j]-32)
{
deinput[i]=((map[j]-'a')-key+26)%26+'a';// Decrypt
}
}
}
deinput[i]='\0';
input[i]='\0';
printf(" Before decryption :%s\n",input);
printf(" After decryption :%s\n",deinput);
}
Chessboard code
#include<stdio.h>
#include<string.h>
void m();
void f1(char map[6][6]);
void getstr(char str[]);
void encrypt(char input[],char map[][6]);// encryption
void decode(char input[],char map[][6]);// Decrypt
int main()
{
char input[1000];
char map[6][6];
f1(map);
int a = 1;
while(a)
{
m();
scanf("%d",&a);
if(a==0)
break;
else if(a==1)
{
encrypt(input, map);
}
else if(a==2)
{
decode(input, map);
}
else{
getstr(input);
}
}
return 0;
}
void m()
{
printf("-------- Chessboard code -------\n");
printf("--------0. sign out ---------\n");
printf("--------1. encryption ---------\n");
printf("--------2. Decrypt ---------\n");
printf("--------3. Get string ---\n");
}
void f1(char a[6][6])
{
int i,j,z = 0;
for(i = 1;i<=5;i++)
{
for(j = 1;j<=5;j++)
{ if('a'+z=='j') z++;
a[i][j]='a'+z++;
}
}
}
void getstr(char str[])
{
getchar();
gets(str);
}
void encrypt(char input[],char map[][6])
{ printf(" The chessboard encryption is as follows \n");
int i,j,z;
int flag = 0;
for(i = 0;i < strlen(input);i++)
{ flag = 1;
for(j = 1;j<=5;j++)
{
if(flag == 0)
break;
for(z = 1;z<=5;z++)
{ if(input[i]=='j')
{
printf("%d%d ",2,4);
flag = 0;
break;
}
if(map[j][z]==input[i])
{
printf("%d%d ",j,z);
flag = 0;
break;
}
}
}
}
printf("\n");
}
void decode(char input[],char map[][6])
{ printf(" Do not enter blank spaces ,i And j You need to judge for yourself \n");
int i;
for(i = 0;i<strlen(input);i=i+2)
{
printf("%c",map[input[i]-'0'][input[i+1]-'0']);
}
printf("\n");
}
Fence code
#include<stdio.h>
#include<string.h>
void encrypt(char str[10000]);
void m();
void decrypt(char str[10000]);
int main() {
char str[10000];
int c = 1;
while (c) {
m();
printf(" Please enter your choice :");
scanf("%d", &c);
getchar();
if (c == 1) {
encrypt(str);
} else if (c == 2) {
decrypt(str);
}
}
return 0;
}
void encrypt(char str[10000]) {
printf(" Please enter the string :\n");
gets(str);
int a;
printf(" Please enter the number of fences :");
scanf("%d", &a);
char t[1000][1000];
int len = strlen(str);
int i, j;
int h = len / a, s = len % a;
if (s != 0) h++;
int z = 0;
for (i = 0; i < h; i++) {
int flag = 1;
for (j = 0; j < a; j++) {
t[i][j] = str[z++];
if (z == len) {
flag = 0;
break;
}
}
if (flag == 0)
break;
}
printf("\n Encrypted as :\n");
for (i = 0; i < a; i++) {
for (j = 0; j < h; j++) {
if (t[j][i] != '\0') {
printf("%c", t[j][i]);
}
}
}
printf("\n");
}
void m() {
printf("------- The fence is encrypted -------\n");
printf("-------1, encryption ---------\n");
printf("-------2, Decrypt ---------\n");
printf("-------0, Exit procedure -----\n");
}
void decrypt(char str[10000]) {
printf(" Please enter the string :\n");
gets(str);
int a;
printf(" Please enter the number of fences :");
scanf("%d", &a);
char t[1000][1000];
int len = strlen(str);
int i, j;
int h = len / a, s = len % a;
int z = 0;
for (i = 0; i <a; i++) {
int flag = 1;
h=len/a;
for (j = 0; j < h; j++) {
if((i+1)<=len%a)
h=len/a+1;
t[j][i] = str[z++];
if (z == len) {
flag = 0;
break;
}
}
if(flag==0)
break;
}
printf("\n After decryption :\n");
h=len/a+1;
for (i = 0; i <h; i++) {
for (j = 0; j <a; j++)
{ if(t[i][j]!='\0')
printf("%c",t[i][j]);
}
} printf("\n");
}
Simple RSA
use c Writing explosion longlong 了 , I use... Directly python Write the script
def EnCrypt(m):
print(" Please enter q,p,e")
q,p,e=eval(input())
n=q*p
c=(m**e)%n
print(" The secret is :")
print(c)
def DeCrypt(m):
print(" Please enter q,p,e")
q, p, e = eval(input())
n = q * p
fn=(q-1)*(p-1)
d = 2
while (e*d)%fn!=1:
d=d+1
c = (m ** d) % n
print(" Plaintext is :")
print(c)
print("rsa")
a = 1
while a:
print(' Please enter the number to encrypt and decrypt ')
c = eval(input())
print(" Encryption select 1, Decryption selection 2,")
ch = eval(input())
if ch==1:
EnCrypt(c)
elif ch==2 :
DeCrypt(c)
else:break
While cleaning up the computer files, I suddenly found this , break out .
版权声明
本文为[After the rain &]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210712206511.html
边栏推荐
猜你喜欢

【项目】小帽外卖(五)

作文以记之 ~ 克隆图

VMware提示恢复快照时出错找不到所需文件

Usage of go language log Uber go / zap / lumberjack

sys.stdin.readline和readlines以及input()

Apache solr 远程代码执行漏洞(CVE-2019-0193)复现

亿级流量多级缓存架构

Actual JDBC connection to MySQL database

ECS uses FRP to map Apache on the local (win10 / win11) intranet to the extranet

Valentina Studio Pro for MAC (MAC database management software)
随机推荐
【以太网交换安全】---端口安全及MAC地址飘移防止与检测
树的基本概念与存储结构
Question bank and answers of Electrical Engineering (elementary) examination in 2022
Valentina Studio Pro for MAC (MAC database management software)
模块化的概念
Sword finger offer day22 bit operation (medium)
Modular concept
2022G3锅炉水处理考试题库及答案
C a complete class that generates Chinese amount and reads it out by voice
天梯赛L3
【面试普通人VS高手系列】b树和b+树的理解
Solution of losing Beijing time zone in window system
Installer mongodb
【一、xxx病虫害检测项目】3、损失函数尝试:Focal loss
数据探索性分析(EDA)之数据分布、相关性分析及可视化方法
Replication of Apache Solr Remote Code Execution Vulnerability (cve-2019-0193)
【2022DASCTF X SU】 三月春季挑战赛 web复现
Unable to infer base url. This is common when using dynamic servlet registration or when the API is
webrtc+srs(sfu)
NAS purchase reference comparison