package egnima;
import java.util.Scanner;
public class enigma {
static public void main(String []args)
{
Scanner cin=new Scanner(System.in);
System.out.print("Input 0 to encode message and 1 to decode message:");
int op=cin.nextInt();
if(op==0)
encode();
else
decode();
}
static void encode()
{
String msg="";
String encodemsg="";
int count=0;
System.out.printf("%s","Input the message:");
Scanner cin=new Scanner(System.in);
msg=cin.nextLine();
for(int i=0;i<msg.length();i++)
{
if((Character.isSpace(msg.charAt(i))))
{
encodemsg+=" ";
}
else if((msg.charAt(i)-count)<'a')
encodemsg+=(char)(msg.charAt(i)+26-count);
else
encodemsg+=(char)(msg.charAt(i)-count);
count++;
}
System.out.println(decodemsg);
}
static void decode()
{
String msg="";
String decodemsg=
Java 简单实现Enigma英格玛密码
最新推荐文章于 2024-05-30 21:05:59 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)