當前位置:首頁 » 密碼管理 » 一行電文加密

一行電文加密

發布時間: 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));

}

熱點內容
betweenand的用法sql 發布:2025-05-14 18:39:25 瀏覽:248
tplink攝像頭存儲卡格式化 發布:2025-05-14 18:37:08 瀏覽:345
安卓平板怎麼安裝excel的軟體 發布:2025-05-14 18:35:44 瀏覽:40
廣州數控圓弧編程實例 發布:2025-05-14 18:25:00 瀏覽:399
搭建伺服器能使用nodejs開發嗎 發布:2025-05-14 18:24:14 瀏覽:134
alook瀏覽器安卓哪個版本上網最快 發布:2025-05-14 18:22:33 瀏覽:456
sqldist 發布:2025-05-14 18:08:18 瀏覽:162
人行外管局編譯 發布:2025-05-14 18:07:33 瀏覽:649
安卓手機如何使用大流量 發布:2025-05-14 17:47:34 瀏覽:82
精密模具編程 發布:2025-05-14 17:45:16 瀏覽:499