当前位置:首页 » 密码管理 » 一行电文加密

一行电文加密

发布时间: 2022-06-12 11:10:29

python电文加密

##注意:最左边每个=表示一个空格

def encrypt(t):

====s=""

====for e in t:

========if e.islower():

============s+=chr(97+(ord(e)-97+7)%26)

========elif e.isupper():

============s+=chr(65+(ord(e)-65+7)%26)

========else:

============s+=e

====return s

t=input()

print(t,encrypt(t))

Ⅱ 用c语言编程:对一行电文进行加密,每个字符转换为字母表中循环右移的第三的字母,如:a-b,b-e.....大写字

#include<stdio.h>

voidchange(chars[]){
inti;
for(i=0;s[i];++i){
if(s[i]>='a'&&s[i]<='z')
s[i]=(s[i]+2-'a')%26+'a';
elseif(s[i]>='A'&&s[i]<='Z')
s[i]=(s[i]+2-'A')%26+'A';
}
}

intmain(){
chars[256];
printf("输入一个字符串:");
scanf("%s",s);
change(s);
printf("转换后为:%s ",s);
return0;
}

Ⅲ 电文加密

#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
char s1[1100], s2[1100];
int s[1100];
int key, len, i, j;
void cpy()
{
int k = 0;
while (k != key)
{
if (!s[++j] && j < len)
k++;
if (j >= len)
j = j - len - 1;
}
s2[j] = s1[i];
s[j] = 1;
}
void cpy2()
{
int k = 0;
while (k != -key)
{
if (!s[++j] && j < len)
k++;
if (j >= len)
j = j - len - 1;
}
s2[i] = s1[j];
s[j] = 1;
}
int main()
{
#ifdef LOCAL
freopen("judge for e\\test\\1.in", "r", stdin);
freopen("judge for e\\test\\1.out", "w", stdout);
#endif
int c = 0;
while (cin >> key)
{
cout << "Case " << ++c << ":" << endl;
cin.getline(s1, 1);
cin.getline(s1, 1000);
len = strlen(s1);
memset(s, 0, sizeof(s));
if (key > 1)
for (i = 0, j = -1; i < len; i++)
cpy();
if (key < -1)
for (i = 0, j = -1; i < len; i++)
cpy2();
s2[len] = *\0*;
cout << s2 << endl;
cout << endl;
}
return 0;
}

Ⅳ C++加密解密电文

没分

Ⅳ 用java语言怎么写: 有一行电文,已按下面规律编译成密码: A->Z a->z B

按照你的要求,编写的Java语言加密程序如下:

publicclassBBE{
publicstaticStringencrypt(Strings){
Stringcryptograph="";
for(inti=0;i<s.length();i++){
charch=s.charAt(i);
if(Character.isLetter(ch)==true){
if(Character.isLowerCase(ch)==true){
charc=(char)('a'+(25-(ch-'a')));
cryptograph=cryptograph+c;
}
if(Character.isUpperCase(ch)==true){
charc=(char)('A'+(25-(ch-'A')));
cryptograph=cryptograph+c;
}
}else{
cryptograph=cryptograph+ch;
}
}
returncryptograph;
}
publicstaticvoidmain(String[]args){
Strings="wearetheworld.";
System.out.println(encrypt(s));
}
}

运行结果:

dv ziv gsv dliow.

Ⅵ 有一行电文,已按下面规律译成密码:

//这个加密算法也就是解密算法,也就是再把密文加密一次就是原文了

#include <stdio.h>
char enc(char ch)
{
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
{
if(ch>='a')
{
ch+=('a'+13-ch)*2-1;
}
else
{
ch+=('A'+13-ch)*2-1;
}
}
return ch;
}

int main()
{
char s[20]="123abcmz8ABMZN";
int i=0;
while(*(s+i))
{
s[i]=enc(s[i]);
i++;
}
printf("加密后:%s\n",s);
i=0;
while(*(s+i))
{
s[i]=enc(s[i]);
i++;
}
printf("原 文:%s\n",s);
return 0;
}

Ⅶ c语言:有一行电文,按如下规律加密,将每个字母变为其后的第四个字母,非字母字符不变,电文从键盘输入,

是不是后移四位啊,就是a变为e
-------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#define MAXLINE 100
void code(char *);

void main()
{
char line[MAXLINE];
printf("Input the string:");
gets(line);
code(line);
printf("The result is: %s\n",line);
}

void code(char *s)
{
while (*s!='\0')
{
if((*s>='a' && *s<='v')||(*s>='A' && *s<='V'))
*s= *s+4;
else if((*s>='w' && *s<='z')||(*s>='W' && *s<='Z'))
*s=*s+4-26;
s=s+1;
}
}

Ⅷ 电文进行加密

public class Test1 {
public static void main(String[] args) {
String msg = "abcde123";
char[] cs = msg.toCharArray();
for (int i = 0; i < cs.length; i++) {
// 每个字母进行加密
cs[i] = change(cs[i]);
}
System.out.println(new String(cs));
}

/**
*
*
* @param c
* @return
*/
public static char change(char c) {
if (c >= 'a' && c <= 'z') {
c = (char) ((c - 'a' + 3) % 26 + 'a');
} else if (c >= 'A' && c <= 'Z') {
c = (char) ((c - 'A' + 3) % 26 + 'A');
}

return c;
}
}

Ⅸ C语言的程序设计 电文加密,每个字母转换为字母表中循环右移的第三个字母。

//对一行电文进行加密,每个字母转换为字母表中循环右移的第三个字母
//大写字母C加密后的ASCII码值为(c-62)%26+65
//小写字母C加密后的ASCII码值为(c-94)%26+97
#include<stdio.h>
void main()
{
//定义数组a和b,以及控制变量i
char a[3];
char b[3];
int i;

//提示输入三个字母
printf("请输入三个字母不要用空格隔开\n");
//用for循环控制接受字母
for(i=0;i<3;i++)
scanf("%c",&a[i]);

//在下一循环前加入该句
printf("经加密后为:");

//用for循环计算加密后的字母的ASCII值
for(i=0;i<=2;i++)
{
if(a[i]>=97)
b[i]=(a[i]-94)%26+97;
if(a[i]>=65&&a[i]<97)
b[i]=(a[i]-62)%26+65;
//输出结果
printf("%c",b[i]);
}
printf("\n");
}

Ⅹ 电文(字符串)加密,形成密码文(字符串)的问题

以前做过完全一样的啊,给,已经编译运行确认:

#include <stdio.h>
#include <string.h>
#include <malloc.h>

typedef struct node
{
char ch;
struct node *forward; /*链接下一节点*/
struct node *backward; /*链接前一节点*/
} CODE;

char *decode(char *ocode, int key)
{
char *ncode;
int length, count,i;
CODE *loop , *p;
length = strlen(ocode);
loop= (CODE*)malloc(length*sizeof(CODE)); /*动态分配密文环*/
for(i=0;i<length-1;i++)
{
loop[i].forward = &loop[i+1];
loop[i].backward =&loop[i-1];

}
loop[0].backward =&loop[length-1];
loop[0].forward = &loop[1];
loop[length-1].forward = loop;
loop[length-1].backward = &loop[length-2];

for(p=loop, i=0; i<length;i++)
{
/*产生密文链表*/
for(count=1;count<key; count++)
p= p->forward;
p->ch =*ocode++;
p->backward->forward =p->forward;
p->forward->backward = p->backward;
p = p->forward;
}
ncode = (char*)malloc((length+1)*sizeof(char));
for(i=0;i<length;i++)

ncode[i] =loop[i].ch;
ncode[length] = '\0';
return ncode;
}

void main()
{
char ocode[256];
int key, num=0;
printf("输入原文字符串: ");
while(num<255&&(ocode[num++]=getchar())!='\n');
ocode[(num==255)?num:num-1] ='\0';
do
{
printf("输入加密密钥:");
scanf("%d",&key);

} while(key<=1);
printf("电文的密码是: %s\n",decode(ocode,key));

}

热点内容
隆地优选交易密码是什么 发布:2025-05-14 21:53:23 浏览:93
强酸强碱存储柜 发布:2025-05-14 21:45:16 浏览:563
车辆参数配置包括什么 发布:2025-05-14 21:31:03 浏览:162
怎么引入安卓项目 发布:2025-05-14 21:26:39 浏览:824
游戏辅编程 发布:2025-05-14 21:18:49 浏览:687
三菱plc一段二段密码什么意思 发布:2025-05-14 21:17:16 浏览:527
电脑开机密码忘记了怎么破解 发布:2025-05-14 21:09:40 浏览:57
pythondict格式 发布:2025-05-14 21:09:38 浏览:886
落叶片拍摄脚本 发布:2025-05-14 20:40:49 浏览:799
安卓为什么不能用cmwap 发布:2025-05-14 20:40:43 浏览:658