這是Herr Deng桑的教學blog,主要處理作業與班導事務,另外還有數位小品。
public class CS { static String encrypt(String plaintext, int key){ char [] m=plaintext.toCharArray(); char [] c=new char[m.length]; for (int i=0; i<c.length; i++) m[i]=(char)((c[i]-'a'+26-key)%26+'A'); String ciphertext=new String(m); return ciphertext; } public static void main(String[] args) { String plaintext="caesar"; int key=3; System.out.println(encrypt(plaintext,key)); }}
seventeen
SEVENTEEN
public class CaesarShiftCipher {static String encrypt(String plaintext, int key){plaintext=plaintext.replace(" ","").toLowerCase();char [] m=plaintext.toCharArray();char [] c=new char[m.length];for (int i=0; i<m.length; i++)c[i]=(char)((m[i]-'a'+26+key)%26+'A');String ciphertext=new String(c);return ciphertext;}static String decrypt(String ciphertext, int key){char [] c=ciphertext.toCharArray();char [] m=new char[c.length];for (int i=0; i<c.length; i++)m[i]=(char)((c[i]-'A'+26-key)%26+'a');String plaintext=new String(m);return plaintext;}public static void main(String[] args) {String plaintext="JVMVEKVVE";int key=9;String ciphertext=encrypt(plaintext, key );System.out.println(ciphertext);System.out.println(decrypt(ciphertext, key));}}key=9SEVENTEEN
public class CaesarShiftCipher {static String encrypt(String plaintext, int key){plaintext=plaintext.replace(" ","").toLowerCase();char [] m=plaintext.toCharArray();char [] c=new char[m.length];for (int i=0; i<m.length; i++)c[i]=(char)((m[i]-'a'+26+key)%26+'A');String ciphertext=new String(c);return ciphertext;}static String decrypt(String ciphertext, int key){char [] c=ciphertext.toCharArray();char [] m=new char[c.length];for (int i=0; i<c.length; i++)m[i]=(char)((c[i]-'A'+26-key)%26+'a');String plaintext=new String(m);return plaintext;}public static void main(String[] args) {String plaintext="JVMVEKVVE";int key=9;String ciphertext=encrypt(plaintext, key );System.out.println(ciphertext);System.out.println(decrypt(ciphertext, key));}}
public class ex1 { static String encrypt(String plaintext, int key){ char [] m=plaintext.toCharArray(); char [] c=new char[m.length]; for (int i=0; i<c.length; i++) m[i]=(char)((c[i]-'a'+26-key)%26+'A'); String ciphertext=new String(m); return ciphertext; } public static void main(String[] args) { String plaintext="caesar"; int key=3; System.out.println(encrypt(plaintext,key)); }}
key:17明文:seventeen
public class aaa{ public static void main(String[] args) { String ciphertext="JVMVEKVVE"; for (int key=1;key<=26;key++) System.out.println(decrypt(ciphertext,key)); } static String decrypt(String ciphertext, int key){ char [] c=ciphertext.toCharArray(); char [] m=new char[c.length]; for (int i=0; i<c.length; i++) m[i]=(char)((c[i]-'A'+26-key)%26+'a'); String plaintext=new String(m); return plaintext; }}
package p1;public class ket { public static void main(String[] args) { String ciphertext="JVMVEKVVE"; for (int key=1;key<=26;key++) System.out.println(decrypt(ciphertext,key)); } static String decrypt(String ciphertext, int key){ char [] c=ciphertext.toCharArray(); char [] m=new char[c.length]; for (int i=0; i<c.length; i++) m[i]=(char)((c[i]-'A'+26-key)%26+'a'); String plaintext=new String(m); return plaintext; }}
package p1;public class san { public static void main(String[] args) { String ciphertext="JVMVEKVVE"; for (int key=1;key<=26;key++) System.out.println(decrypt(ciphertext,key)); } static String decrypt(String ciphertext, int key){ char [] c=ciphertext.toCharArray(); char [] m=new char[c.length]; for (int i=0; i<c.length; i++) m[i]=(char)((c[i]-'A'+26-key)%26+'a'); String plaintext=new String(m); return plaintext; }}
package p1;public class wie { public static void main(String[] args) { String ciphertext="JVMVEKVVE"; for (int key=1;key<=26;key++) System.out.println(decrypt(ciphertext,key)); } static String decrypt(String ciphertext, int key){ char [] c=ciphertext.toCharArray(); char [] m=new char[c.length]; for (int i=0; i<c.length; i++) m[i]=(char)((c[i]-'A'+26-key)%26+'a'); String plaintext=new String(m); return plaintext; }}
public class ex1{static String encrypt(String plaintext, int key){char [] m=plaintext.toCharArray();char [] c=new char[m.length];for (int i=0; i<c.length; i++)m[i]=(char)((c[i]-'a'+26-key)%26+'A');String ciphertext=new String(m);return ciphertext;}public static void main(String[] args) {String plaintext="caesar";int key=3;System.out.println(encrypt(plaintext,key));}}
程式碼太長了我簡短說明int key=9;明文:SEVENTEEN
public class Caesar { public static void main(String[] args) { String ciphertext="JVMVEKVVE"; for (int key=1;key<26;key++) System.out.println("key="+key+" "+decrypt(ciphertext,key)); } static String decrypt(String ciphertext, int key){ char [] c=ciphertext.toCharArray(); char [] m=new char[c.length]; for (int i=0; i<c.length; i++) m[i]=(char)((c[i]-'A'+26-key)%26+'a'); String plaintext=new String(m); return plaintext; } }
package p1;public class wie {public static void main(String[] args) {String ciphertext="JVMVEKVVE";for (int key=1;key<=26;key++)System.out.println(decrypt(ciphertext,key));}static String decrypt(String ciphertext, int key){char [] c=ciphertext.toCharArray();char [] m=new char[c.length];for (int i=0; i<c.length; i++)m[i]=(char)((c[i]-'A'+26-key)%26+'a');String plaintext=new String(m);return plaintext;}}key:17明文:seventeen
SeventeenKey=17
B10133139_林志鴻資管二丙public class CaesarShiftCipher {static String encrypt(String plaintext, int key){plaintext=plaintext.replace(" ","").toLowerCase();char [] m=plaintext.toCharArray();char [] c=new char[m.length];for (int i=0; i<m.length; i++)c[i]=(char)((m[i]-'a'+26+key)%26+'A');String ciphertext=new String(c);return ciphertext;}static String decrypt(String ciphertext, int key){char [] c=ciphertext.toCharArray();char [] m=new char[c.length];for (int i=0; i<c.length; i++)m[i]=(char)((c[i]-'A'+26-key)%26+'a');String plaintext=new String(m);return plaintext;}public static void main(String[] args) {String plaintext="JVMVEKVVE";int key=9;String ciphertext=encrypt(plaintext, key );System.out.println(ciphertext);System.out.println(decrypt(ciphertext, key));}}
key:明文:SEVENTEEN
Key:17明文:SEVENTEEN
SEVENTEEN 金鑰為17
金鑰為17SEVENTEEN
public class Caesar { public static void main(String[] args) { String ciphertext="JVMVEKVVE"; for (int key=1;key<=26;key++) System.out.println(decrypt(ciphertext,key)); } static String decrypt(String ciphertext, int key){ char [] c=ciphertext.toCharArray(); char [] m=new char[c.length]; for (int i=0; i<c.length; i++) m[i]=(char)((c[i]-'A'+26-key)%26+'a'); String plaintext=new String(m); return plaintext; }}
package AA111;public class ket {public static void main(String[] args) {String ciphertext="JVMVEKVVE";for (int key=1;key<=26;key++)System.out.println(decrypt(ciphertext,key));}static String decrypt(String ciphertext, int key){char [] c=ciphertext.toCharArray();char [] m=new char[c.length];for (int i=0; i<c.length; i++)m[i]=(char)((c[i]-'A'+26-key)%26+'a');String plaintext=new String(m);return plaintext;}}
package p1;public class key {public static void main(String[] args) {String ciphertext="JVMVEKVVE";for (int key=1;key<=26;key++)System.out.println(decrypt(ciphertext,key));}static String decrypt(String ciphertext, int key){char [] c=ciphertext.toCharArray();char [] m=new char[c.length];for (int i=0; i<c.length; i++)m[i]=(char)((c[i]-'A'+26-key)%26+'a');String plaintext=new String(m);return plaintext;}}
package p1;public class san {public static void main(String[] args) {String ciphertext="JVMVEKVVE";for (int key=1;key<=26;key++)System.out.println(decrypt(ciphertext,key));}static String decrypt(String ciphertext, int key){char [] c=ciphertext.toCharArray();char [] m=new char[c.length];for (int i=0; i<c.length; i++)m[i]=(char)((c[i]-'A'+26-key)%26+'a');String plaintext=new String(m);return plaintext;}}
key:17明 :seventeen
public class abc{public static void main(String[] args) {String ciphertext="JVMVEKVVE";for (int key=1;key<=26;key++)System.out.println(decrypt(ciphertext,key));}static String decrypt(String ciphertext, int key){char [] c=ciphertext.toCharArray();char [] m=new char[c.length];for (int i=0; i<c.length; i++)m[i]=(char)((c[i]-'A'+26-key)%26+'a');String plaintext=new String(m);return plaintext;}}
public class ex {static String encrypt(String plaintext, int key){char [] m=plaintext.toCharArray();char [] c=new char[m.length];for (int i=0; i<c.length; i++)m[i]=(char)((c[i]-'a'+26-key)%26+'A');String ciphertext=new String(m);return ciphertext;}public static void main(String[] args) {String plaintext="caesar";int key=3;System.out.println(encrypt(plaintext,key));}}
b10041032林佳雯public class Caesar {public static void main(String[] args) {String ciphertext="JVMVEKVVE";for (int key=1;key<26;key++)System.out.println("key="+key+" "+decrypt(ciphertext,key));}static String decrypt(String ciphertext, int key){char [] c=ciphertext.toCharArray();char [] m=new char[c.length];for (int i=0; i<c.length; i++)m[i]=(char)((c[i]-'A'+26-key)%26+'a');String plaintext=new String(m);return plaintext;}}
public class CS {static String encrypt(String plaintext, int key){char [] m=plaintext.toCharArray();char [] c=new char[m.length];for (int i=0; i<c.length; i++)m[i]=(char)((c[i]-'a'+26-key)%26+'A');String ciphertext=new String(m);return ciphertext;}public static void main(String[] args) {String plaintext="caesar";int key=3;System.out.println(encrypt(plaintext,key));}}
public class CSC {static String encrypt(String plaintext, int keys){char [] m=plaintext.toCharArray();char [] c=new char[m.length];for (int i=0; i<c.length; i++)m[i]=(char)((c[i]-'a'+26-keys)%26+'A');String ciphertext=new String(m);return ciphertext;}public static void main(String[] args) {String plaintext="caesar";int keys=3;System.out.println(encrypt(plaintext,key));}}
public class CS {static String encrypt(String plaintext, int keys){char [] m=plaintext.toCharArray();char [] c=new char[m.length];for (int i=0; i<c.length; i++)m[i]=(char)((c[i]-'a'+26-keys)%26+'A');String ciphertext=new String(m);return ciphertext;}public static void main(String[] args) {String plaintext="caesar";int keys=3;System.out.println(encrypt(plaintext,keys));}}
張貼留言
54 則留言:
public class CS {
static String encrypt(String plaintext, int key){
char [] m=plaintext.toCharArray();
char [] c=new char[m.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'a'+26-key)%26+'A');
String ciphertext=new String(m);
return ciphertext;
}
public static void main(String[] args) {
String plaintext="caesar";
int key=3;
System.out.println(encrypt(plaintext,key));
}
}
seventeen
SEVENTEEN
public class CaesarShiftCipher {
static String encrypt(String plaintext, int key){
plaintext=plaintext.replace(" ","").
toLowerCase();
char [] m=plaintext.toCharArray();
char [] c=new char[m.length];
for (int i=0; i<m.length; i++)
c[i]=(char)((m[i]-'a'+26+key)%26+'A');
String ciphertext=new String(c);
return ciphertext;
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
public static void main(String[] args) {
String plaintext="JVMVEKVVE";
int key=9;
String ciphertext=encrypt(plaintext, key );
System.out.println(ciphertext);
System.out.println(decrypt(ciphertext, key));
}
}
key=9
SEVENTEEN
public class CaesarShiftCipher {
static String encrypt(String plaintext, int key){
plaintext=plaintext.replace(" ","").
toLowerCase();
char [] m=plaintext.toCharArray();
char [] c=new char[m.length];
for (int i=0; i<m.length; i++)
c[i]=(char)((m[i]-'a'+26+key)%26+'A');
String ciphertext=new String(c);
return ciphertext;
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
public static void main(String[] args) {
String plaintext="JVMVEKVVE";
int key=9;
String ciphertext=encrypt(plaintext, key );
System.out.println(ciphertext);
System.out.println(decrypt(ciphertext, key));
}
}
public class ex1 {
static String encrypt(String plaintext, int key){
char [] m=plaintext.toCharArray();
char [] c=new char[m.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'a'+26-key)%26+'A');
String ciphertext=new String(m);
return ciphertext;
}
public static void main(String[] args) {
String plaintext="caesar";
int key=3;
System.out.println(encrypt(plaintext,key));
}
}
key:17
明文:seventeen
public class aaa
{
public static void main(String[] args)
{
String ciphertext="JVMVEKVVE";
for (int key=1;key<=26;key++)
System.out.println(decrypt(ciphertext,key));
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
}
package p1;
public class ket
{
public static void main(String[] args)
{
String ciphertext="JVMVEKVVE";
for (int key=1;key<=26;key++)
System.out.println(decrypt(ciphertext,key));
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
}
package p1;
public class san
{
public static void main(String[] args)
{
String ciphertext="JVMVEKVVE";
for (int key=1;key<=26;key++)
System.out.println(decrypt(ciphertext,key));
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
}
package p1;
public class wie
{
public static void main(String[] args)
{
String ciphertext="JVMVEKVVE";
for (int key=1;key<=26;key++)
System.out.println(decrypt(ciphertext,key));
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
}
public class ex1{
static String encrypt(String plaintext, int key){
char [] m=plaintext.toCharArray();
char [] c=new char[m.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'a'+26-key)%26+'A');
String ciphertext=new String(m);
return ciphertext;
}
public static void main(String[] args) {
String plaintext="caesar";
int key=3;
System.out.println(encrypt(plaintext,key));
}
}
程式碼太長了
我簡短說明
int key=9;
明文:SEVENTEEN
public class Caesar
{
public static void main(String[] args)
{
String ciphertext="JVMVEKVVE";
for (int key=1;key<26;key++)
System.out.println("key="+key+" "+decrypt(ciphertext,key));
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
}
package p1;
public class wie
{
public static void main(String[] args)
{
String ciphertext="JVMVEKVVE";
for (int key=1;key<=26;key++)
System.out.println(decrypt(ciphertext,key));
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
}
key:17
明文:seventeen
Seventeen
Key=17
B10133139_林志鴻
資管二丙
public class CaesarShiftCipher {
static String encrypt(String plaintext, int key){
plaintext=plaintext.replace(" ","").
toLowerCase();
char [] m=plaintext.toCharArray();
char [] c=new char[m.length];
for (int i=0; i<m.length; i++)
c[i]=(char)((m[i]-'a'+26+key)%26+'A');
String ciphertext=new String(c);
return ciphertext;
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
public static void main(String[] args) {
String plaintext="JVMVEKVVE";
int key=9;
String ciphertext=encrypt(plaintext, key );
System.out.println(ciphertext);
System.out.println(decrypt(ciphertext, key));
}
}
public class CaesarShiftCipher {
static String encrypt(String plaintext, int key){
plaintext=plaintext.replace(" ","").
toLowerCase();
char [] m=plaintext.toCharArray();
char [] c=new char[m.length];
for (int i=0; i<m.length; i++)
c[i]=(char)((m[i]-'a'+26+key)%26+'A');
String ciphertext=new String(c);
return ciphertext;
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
public static void main(String[] args) {
String plaintext="JVMVEKVVE";
int key=9;
String ciphertext=encrypt(plaintext, key );
System.out.println(ciphertext);
System.out.println(decrypt(ciphertext, key));
}
}
key=9
SEVENTEEN
key:
明文:SEVENTEEN
Key:17
明文:SEVENTEEN
SEVENTEEN
SEVENTEEN
SEVENTEEN
SEVENTEEN
SEVENTEEN
金鑰為17
金鑰為17
SEVENTEEN
seventeen
Seventeen
Key=17
public class Caesar
{
public static void main(String[] args)
{
String ciphertext="JVMVEKVVE";
for (int key=1;key<=26;key++)
System.out.println(decrypt(ciphertext,key));
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
}
seventeen
key:17
明文:seventeen
package AA111;
public class ket
{
public static void main(String[] args)
{
String ciphertext="JVMVEKVVE";
for (int key=1;key<=26;key++)
System.out.println(decrypt(ciphertext,key));
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
}
package p1;
public class key
{
public static void main(String[] args)
{
String ciphertext="JVMVEKVVE";
for (int key=1;key<=26;key++)
System.out.println(decrypt(ciphertext,key));
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
}
package p1;
public class san
{
public static void main(String[] args)
{
String ciphertext="JVMVEKVVE";
for (int key=1;key<=26;key++)
System.out.println(decrypt(ciphertext,key));
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
}
SEVENTEEN
SEVENTEEN
key:17
明 :seventeen
seventeen
public class CaesarShiftCipher {
static String encrypt(String plaintext, int key){
plaintext=plaintext.replace(" ","").
toLowerCase();
char [] m=plaintext.toCharArray();
char [] c=new char[m.length];
for (int i=0; i<m.length; i++)
c[i]=(char)((m[i]-'a'+26+key)%26+'A');
String ciphertext=new String(c);
return ciphertext;
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
public static void main(String[] args) {
String plaintext="JVMVEKVVE";
int key=9;
String ciphertext=encrypt(plaintext, key );
System.out.println(ciphertext);
System.out.println(decrypt(ciphertext, key));
}
}
public class abc
{
public static void main(String[] args)
{
String ciphertext="JVMVEKVVE";
for (int key=1;key<=26;key++)
System.out.println(decrypt(ciphertext,key));
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
}
public class ex {
static String encrypt(String plaintext, int key){
char [] m=plaintext.toCharArray();
char [] c=new char[m.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'a'+26-key)%26+'A');
String ciphertext=new String(m);
return ciphertext;
}
public static void main(String[] args) {
String plaintext="caesar";
int key=3;
System.out.println(encrypt(plaintext,key));
}
}
Seventeen
Key=17
SEVENTEEN
public class CaesarShiftCipher {
static String encrypt(String plaintext, int key){
plaintext=plaintext.replace(" ","").
toLowerCase();
char [] m=plaintext.toCharArray();
char [] c=new char[m.length];
for (int i=0; i<m.length; i++)
c[i]=(char)((m[i]-'a'+26+key)%26+'A');
String ciphertext=new String(c);
return ciphertext;
}
static String decrypt(String ciphertext, int key){
char [] c=ciphertext.toCharArray();
char [] m=new char[c.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'A'+26-key)%26+'a');
String plaintext=new String(m);
return plaintext;
}
public static void main(String[] args) {
String plaintext="JVMVEKVVE";
int key=9;
String ciphertext=encrypt(plaintext, key );
System.out.println(ciphertext);
System.out.println(decrypt(ciphertext, key));
}
}
SEVENTEEN
seventeen
b10041032林佳雯
public class Caesar {public static void main(String[] args) {String ciphertext="JVMVEKVVE";for (int key=1;key<26;key++)System.out.println("key="+key+" "+decrypt(ciphertext,key));}static String decrypt(String ciphertext, int key){char [] c=ciphertext.toCharArray();char [] m=new char[c.length];for (int i=0; i<c.length; i++)m[i]=(char)((c[i]-'A'+26-key)%26+'a');String plaintext=new String(m);return plaintext;}}
seventeen
public class ex1{
static String encrypt(String plaintext, int key){
char [] m=plaintext.toCharArray();
char [] c=new char[m.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'a'+26-key)%26+'A');
String ciphertext=new String(m);
return ciphertext;
}
public static void main(String[] args) {
String plaintext="caesar";
int key=3;
System.out.println(encrypt(plaintext,key));
}
}
public class ex1{
static String encrypt(String plaintext, int key){
char [] m=plaintext.toCharArray();
char [] c=new char[m.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'a'+26-key)%26+'A');
String ciphertext=new String(m);
return ciphertext;
}
public static void main(String[] args) {
String plaintext="caesar";
int key=3;
System.out.println(encrypt(plaintext,key));
}
}
key:17
明文:seventeen
public class CS {
static String encrypt(String plaintext, int key){
char [] m=plaintext.toCharArray();
char [] c=new char[m.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'a'+26-key)%26+'A');
String ciphertext=new String(m);
return ciphertext;
}
public static void main(String[] args) {
String plaintext="caesar";
int key=3;
System.out.println(encrypt(plaintext,key));
}
}
public class CSC {
static String encrypt(String plaintext, int keys){
char [] m=plaintext.toCharArray();
char [] c=new char[m.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'a'+26-keys)%26+'A');
String ciphertext=new String(m);
return ciphertext;
}
public static void main(String[] args) {
String plaintext="caesar";
int keys=3;
System.out.println(encrypt(plaintext,key));
}
}
public class CS {
static String encrypt(String plaintext, int keys){
char [] m=plaintext.toCharArray();
char [] c=new char[m.length];
for (int i=0; i<c.length; i++)
m[i]=(char)((c[i]-'a'+26-keys)%26+'A');
String ciphertext=new String(m);
return ciphertext;
}
public static void main(String[] args) {
String plaintext="caesar";
int keys=3;
System.out.println(encrypt(plaintext,keys));
}
}
張貼留言