21 Replies - 2054 Views - Last Post: 22 November 2012 - 07:46 PM
#1
substitution cipher
Posted 14 November 2012 - 11:15 PM
Replies To: substitution cipher
#2
Re: substitution cipher
Posted 15 November 2012 - 04:29 AM
Quote
This post has been edited by g00se: 15 November 2012 - 04:30 AM
Reason for edit:: typo
#4
Re: substitution cipher
Posted 15 November 2012 - 05:06 AM
Quote
#5
Re: substitution cipher
Posted 15 November 2012 - 08:01 AM
class Ceasar {
private Map<Character,Character> map;
public Ceasar() {
String from = "abcdefghijklmnopqrstuvwxyz";
String to = "qwertyuiopasdfghjklzxcvbnm";
map = new HashMap<Character,Character>();
for(int i = 0; i < from.length(); ++i)
map.put(from.charAt(i), to.charAt(i));
}
}
JHol, on 15 November 2012 - 07:47 AM, said:
My link
Nice article by the way.
And the code is here in DIC
http://www.dreaminco...-ceasar-cipher/
as at least 8 other secret codes programs.
#6
Re: substitution cipher
Posted 19 November 2012 - 07:32 PM
map = new HashMap<Character,Character>();
for(int i = 0; i < from.length(); ++i)
map.put(from.charAt(i), to.charAt(i));
and decryption will be using this?
map = new HashMap<Character,Character>();
for(int i = 0; i < from.length(); ++i)
map.put(to.charAt(i), from.charAt(i));
#7
Re: substitution cipher
Posted 19 November 2012 - 07:51 PM
import java.util.HashMap;
public class Caesar {
private HashMap<Character,Character> encr;
private HashMap<Character,Character> decr;
public Caesar() {
String from = "abcdefghijklmnopqrstuvwxyz";
String to = "qwertyuiopasdfghjklzxcvbnm";
encr = new HashMap<Character,Character>();
for(int i = 0; i < from.length(); ++i)
encr.put(from.charAt(i), to.charAt(i));
decr = new HashMap<Character,Character>();
for(int i = 0; i < from.length(); ++i)
decr.put(to.charAt(i), from.charAt(i));
}
}
something like this?
#8
Re: substitution cipher
Posted 19 November 2012 - 08:01 PM
import java.util.HashMap;
public class Caesar {
private HashMap<Character,Character> encr;
private HashMap<Character,Character> decr;
public Caesar() {
String from = "abcdefghijklmnopqrstuvwxyz";
String to = "qwertyuiopasdfghjklzxcvbnm";
encr = new HashMap<Character,Character>();
decr = new HashMap<Character,Character>();
for(int i = 0; i < from.length(); ++i) {
encr.put(from.charAt(i), to.charAt(i));
decr.put(to.charAt(i), from.charAt(i));
}
}
#9
Re: substitution cipher
Posted 19 November 2012 - 08:28 PM
#10
Re: substitution cipher
Posted 19 November 2012 - 08:33 PM
for(int i = 0; i < from.length(); ++i) {
which is:
adding 26 times 1 to i
calling 26 times the method length(| of String from
checking 26 times that i < from.length()
#11
Re: substitution cipher
Posted 20 November 2012 - 04:20 AM
char cipherC = to[from.indexOf(plainC)];
#12
Re: substitution cipher
Posted 21 November 2012 - 06:59 AM
g00se, on 20 November 2012 - 07:20 PM, said:
char cipherC = to[from.indexOf(plainC)];
oh? so with that for encrypt would be
char cipherE = to[from.indexOf(plainC)];
while decrypt would be as below?
char cipherD = from[to.indexOf(plainC)];
g00se, on 20 November 2012 - 07:20 PM, said:
char cipherC = to[from.indexOf(plainC)];
oh? so with that for encrypt would be
char cipherE = to[from.indexOf(plainC)];
while decrypt would be as below?
char cipherD = from[to.indexOf(plainC)];
g00se, on 20 November 2012 - 07:20 PM, said:
char cipherC = to[from.indexOf(plainC)];
and what is the (plainC) refer to? is it plainText?
#13
Re: substitution cipher
Posted 21 November 2012 - 10:03 AM
Quote
Not quite. You need to invert everything:
char cipherC = to[from.indexOf(plainC)]; char plainC = from[to.indexOf(cipherC)];
Quote
#14
Re: substitution cipher
Posted 21 November 2012 - 11:00 AM
char cipherC = to.charAt(from.indexOf(plainC)); char plainC = from.charAt(to.indexOf(cipherC));
#15
Re: substitution cipher
Posted 22 November 2012 - 02:28 AM
which are the input file are consist of both uppercase and lower case alphabet. but the output only able to display uppercase only. and is it possible for me to change ' ' to '#' as well? and i also having some problem in doing the decrypting as well @@ below is the coding that so far i am having now. hope you guys can help me out. @@ and thanks in advance.
import java.util.Scanner;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
public class SubstitutionCipher{
public static final String plainText = "abcdefghijklmnopqrstuvwxyz";
public static String encrypt(String inputWord, String cipherText){
String encryptedString = inputWord.toLowerCase();
for (int i = 0; i < 26; i++){
char cipherTextChar = cipherText.charAt(i);
char plainTextChar = plainText.charAt(i);
encryptedString = encryptedString.replace(plainTextChar,cipherTextChar);
}
return encryptedString;
}
public static void main(String[] args){
String cipherText = "FEATHRZYXWVUSQPONMLKJIGDCB";
System.out.println("Caesar Cipher Encryption\n");
Scanner console = new Scanner(System.in);
System.out.print("Input file: ");
String inputFileName = console.next();
System.out.print("Output file: ");
String outputFileName = console.next();
try{
FileReader reader = new FileReader("C:/"+inputFileName+".txt");
Scanner in = new Scanner(reader);
PrintWriter out = new PrintWriter("C:/"+outputFileName+".txt");
while (in.hasNextLine()){
String line = in.nextLine();
String encipheredText = encrypt(line, cipherText);
System.out.println("Plaintext: " + line);
System.out.println("Ciphertext: " + encipheredText);
out.println(encipheredText);
}
out.close();
}
catch (IOException exception){
System.out.println("Error processing file:" + exception);
}
}
}
and for the
String cipherText = "FEATHRZYXWVUSQPONMLKJIGDCB";this line, it seem that lowercase cant be use @@ any idea to make it lower change to lower, while upper change to upper?
|
|

New Topic/Question
Reply



MultiQuote





|