VC移位算法实现数据的加密解密

本文介绍了如何使用VC移位算法来实现数据的加密和解密过程,通过C语言编写示例代码展示了算法的具体实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

VC移位算法实现数据的加密解密 

 

#include <stdio.h> 

#include <conio.h> 
#include <string.h> 
#include <stdlib.h> 
 
void Shift() 
char c[100]; 
int length, i=0, key=0; 
 
 
printf("/n********Shift Cipher********/nPlease input primal sentence: "); 
gets(c); 
length = strlen(c); 
printf("Input the key(0~26): /n  "); 
scanf("%d", &key); 
getchar(); 
 
if(key<0) 
printf("The value of key is error!/nPress any key to return..."); 
getch(); 
return; 
for(i=0; i<length; i++) 
if(c[i]>96&&c[i]<123) 
c[i] = (c[i]+key-97)%26+97; 
else if(c[i]>64&&c[i]<91) 
c[i] = (c[i]+key-65)%26+65; 
printf("Result is: %s/n", c); 
for(i=0; i<length; i++) 
if(c[i]>64&&c[i]<91) 
c[i] = (c[i]-key-65+26)%26+97; 
printf("/nAfter translated the sentence,we can see the primal sentence as follow:/n%s/n", c); 
getch(); 
 
void jiemi()
{
char d[100];
int extent,j=0,password=0;
 
printf("/n*******shift ciphertext***********/nplease input your ciphertext: ");
gets(d); 
    extent = strlen(d); 
    printf("Input the password(0~26): /n  "); 
    scanf("%d", &password); 
    getchar(); 
 
 
for(j=0; j<extent; j++) 
if(d[j]>96&&d[j]<123) 
d[j] = (d[j]-password-71)%26+97; 
else if(d[j]>64&&d[j]<91) 
d[j] = (d[j]-password-65+26)%26+65; 
printf("Result is: %s/n", d); 
for(j=0; j<extent; j++) 
if(d[j]>64&&d[j]<91) 
d[j] = (
d[j]-password-65+26)%26+97; 
printf("/nAfter translated the sentence,we can see the primal sentence as follow:/n%s/n", d); 
printf("Press any key to return..."); 
getch(); 
 
 
void menu()
{
system("cls");
printf("/n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
printf("/n  您好:以下是替换加密算法~");
printf("/n  pleas select a item:");
printf("/n    no.1:Encrypt the file");
printf("/n    no.2:Decrypt the file");
printf("/n    no.3:Exit");
printf("/n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
}
 
void main() 
int k=0; 
menu();
k=getch();
while(k!=3)
{
if(k=='1')
{
Shift();
break;
}
    else if(k=='2')
{
jiemi();
break;
}
else if(k=='3')
   break;
}
 
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值