Results 1 to 2 of 2
Thread: cipher.. Won't work
- 11-18-2008, 04:05 AM #1
Member
- Join Date
- Sep 2008
- Posts
- 7
- Rep Power
- 0
cipher.. Won't work
I am trying to figure out why this cipher i have will not work. can anyone help?
Java Code:import javax.swing.*; public class Animal { private String inputString; private int intOffset; public Animal() { inputString = null; intOffset = 0; } public static void main(String [] args) { Animal c2 = new Animal(); int choose = JOptionPane.showConfirmDialog(null,"If you want to Encrypet Text Click (Yes) ,or Decrypt Click (No) or Cancel to exit :"); if (choose == JOptionPane.YES_OPTION) { String plainText = c2.encrypt(); JOptionPane.showMessageDialog(null,plainText); } else if(choose == JOptionPane.NO_OPTION) { String cipherText = c2.decrypt(); JOptionPane.showMessageDialog(null,cipherText); } else System.exit(0); } public String encrypt() { inputString = ((String)JOptionPane.showInputDialog("Enter PlainText") ).toLowerCase().trim(); intOffset = Integer.parseInt(JOptionPane.showInputDialog("Enter Key") ); String letters = "abcdefghijklmnopqrstuvwxyz"; StringBuffer sb = new StringBuffer(); int holder = inputString.length(); for(int i = 0; i < holder; i++) { String tmp = ""+inputString.charAt(i); int offset = letters.indexOf(tmp); offset += intOffset; if( offset > 25 ){ int newOffset = 0; newOffset = offset % 26; sb.append( letters.charAt(newOffset) ); } else { sb.append( letters.charAt(offset) ); } // }//forloop return sb.toString(); } public String decrypt() { inputString = ((String)JOptionPane.showInputDialog("Enter CipherText") ).toLowerCase().trim(); intOffset = Integer.parseInt(JOptionPane.showInputDialog("Enter Key") ); String letters = "abcdefghijklmnopqrstuvwxyz"; StringBuffer sb = new StringBuffer(); int holder = inputString.length(); for(int i = 0; i < holder; i++) { String tmp = ""+inputString.charAt(i); int offset = letters.indexOf(tmp); offset -= intOffset; offset %= 26; sb.append( letters.charAt(offset) ); } return sb.toString(); } }
- 11-18-2008, 01:22 PM #2
This is not encipherment.
Study
and see if you can grasp any of it.Java Code:import javax.crypto.Cipher;
( no intent to be hard on you, it's just that this is what came to mind when I put your code in the editor to look at it... )Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Similar Threads
-
Synchronization Doesn't seem to work
By sherinpearl in forum Threads and SynchronizationReplies: 1Last Post: 04-23-2008, 06:30 PM -
Will this applet ever work?
By willemjav in forum Java AppletsReplies: 4Last Post: 04-20-2008, 05:40 PM -
Pass by ref. A work around?
By diRisig in forum New To JavaReplies: 0Last Post: 02-05-2008, 07:25 PM -
how would i get this to work...?
By deeadeed in forum New To JavaReplies: 6Last Post: 12-06-2007, 02:58 AM -
Work On Lucene
By peiceonly in forum LuceneReplies: 1Last Post: 08-07-2007, 05:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks