Results 1 to 1 of 1
Thread: pls check it
- 03-24-2009, 02:35 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 27
- Rep Power
- 0
pls check it
I have try to resolve this problem but if I have any mistake pls tell me...
can anyone explain something about ( k ) what does it need to be
Problem description:
POLYALPHABETIC SUBSTITUTION CIPHERS
As one can readily see, monoalphabetic substitution ciphers are notoriously easy to break.
In the case of the Caesar cipher, the shift value can be uncovered rather easily. One way clas-
sical cryptographers dealt with this was to use different shift values for letters depending on
their position in the text. For example, one may do something like the following:
• Let a1, a2, . . . , an be the letters in a plaintext message. Consider the letter ap:
• If p is divisible by 4, shift ap 7 letters down the alphabet.
• If p is of the form 4k + 1 for some k, shift ap 5 letters down the alphabet.
• If p is of the form 4k + 2 for some k, shift ap 13 letters down the alphabet.
• If p is of the form 4k + 3 for some k, shift ap 2 letters down the alphabet.
source code by me:
Java Code:public class Det4enc { public static void main(String[] args) { String str = "DEFCON FOUR"; System.out.println (str); int key = 0; int k = 1; String encrypted = encrypt(str, key, k); System.out.println(encrypted); } public static String encrypt(String str, int key, int k) { String encrypted = ""; for(int i = 0; i < str.length(); i++) { int c = str.charAt(i); //Caktimi i ndryshimit te qelsit if(i%4==0) key = 7; else if(i%(4*k+1)==0) key = 5; else if(i%(4*k+2)==0) key = 13; else if(i%(4*k+3)==0) key = 2; else key = 0; if (Character.isUpperCase(c)) { c = c + (key % 26); if (c > 'Z') c = c - 26; } else if (Character.isLowerCase(c)) { c = c + (key % 26); if (c > 'z') c = c - 26; } encrypted += (char) c; } return encrypted; } }
Similar Threads
-
how to check java
By funkygarzon in forum New To JavaReplies: 10Last Post: 03-08-2009, 08:39 AM -
Plz Some one check my code
By TamTam in forum AWT / SwingReplies: 1Last Post: 02-07-2009, 11:24 PM -
Check for null int
By SnarfSnarf in forum New To JavaReplies: 5Last Post: 01-30-2009, 11:12 PM -
Check box tag
By elizaabru in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 08-26-2008, 02:37 PM -
spell check
By kazitula in forum Java AppletsReplies: 2Last Post: 12-20-2007, 11:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks