| | |
Encryption problem using key
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2007
Posts: 10
Reputation:
Solved Threads: 0
Hi people,
I am wantng to read a key in as an argument that will duplicate itself to the exact character length as the plaintext , read from a text file.
E.g. key = deceptive
Then i need it to repeat until the end of the plaintext file length as below:
Key: deceptivedeceptivedeceptive (incremented to exact length as plaintext)
Plaintext: wearediscoveredsaveyourself (read from a file)
Ciphertext: ZICVTWQNGRZGVTWAVZHCQYGLMGJ (output text)
At the moment i have converted my key and plaintext into 2 integer arrays, ready to do my algorithm in order to get my ciphertext.
I am assuming i will need to add some sort of a counter, but Any ideas of how to do this?
Thanks
I am wantng to read a key in as an argument that will duplicate itself to the exact character length as the plaintext , read from a text file.
E.g. key = deceptive
Then i need it to repeat until the end of the plaintext file length as below:
Key: deceptivedeceptivedeceptive (incremented to exact length as plaintext)
Plaintext: wearediscoveredsaveyourself (read from a file)
Ciphertext: ZICVTWQNGRZGVTWAVZHCQYGLMGJ (output text)
At the moment i have converted my key and plaintext into 2 integer arrays, ready to do my algorithm in order to get my ciphertext.
I am assuming i will need to add some sort of a counter, but Any ideas of how to do this?
Thanks
Well it looks like the Vigenere cipher, am I correct?
You would need two loops. The outer one monitoring the overall length of the string. The inner loop monitoring the length of the key.
I believe that should work.
You would need two loops. The outer one monitoring the overall length of the string. The inner loop monitoring the length of the key.
Java Syntax (Toggle Plain Text)
Pseudocode string key = "blah" string input = "my string" string cipherstring = "" for(i=0;i<input.length;i+=key.length) { for(k=0;k<key.length;k++) { cipherstring += key[k] //concatenate } }
I believe that should work.
Last edited by ShawnCplus; Dec 6th, 2007 at 3:12 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
•
•
Join Date: Dec 2007
Posts: 10
Reputation:
Solved Threads: 0
thank you, but i dont think it works.
Here is a snippet of my code:
for ( int i = 0; i < file.length;i+=key.length)
{
for (int k = 0; k <key.length;k++)
{
file[i] += file[i] + key[k];
System.out.println(i);
System.out.println(k);
Here are the results:
i:0
k:0
i:0
k:1
i:0
k:2
i:0
k:3
i:0
k:4
i:0
k:5
i:0
k:6
i:0
k:7
i:0
k:8
i:0
k:9
i:10
k:0
i:10
k:1
i:10
k:2
i:10
k:3
i:10
k:4
i:10
k:5
and so on.
My key length (k) was 10 in this case.
Can you tell me please why (i) suddenly goes from 0 to 10 after the key has been re-used?
i need to someone get (i) to incease up to the last character in my file.
Thanks for any help
Here is a snippet of my code:
for ( int i = 0; i < file.length;i+=key.length)
{
for (int k = 0; k <key.length;k++)
{
file[i] += file[i] + key[k];
System.out.println(i);
System.out.println(k);
Here are the results:
i:0
k:0
i:0
k:1
i:0
k:2
i:0
k:3
i:0
k:4
i:0
k:5
i:0
k:6
i:0
k:7
i:0
k:8
i:0
k:9
i:10
k:0
i:10
k:1
i:10
k:2
i:10
k:3
i:10
k:4
i:10
k:5
and so on.
My key length (k) was 10 in this case.
Can you tell me please why (i) suddenly goes from 0 to 10 after the key has been re-used?
i need to someone get (i) to incease up to the last character in my file.
Thanks for any help
Because each increment the length of the key is added to i. This makes it so the key string doesn't become longer than the string to be encrypted.
The loop will keep going until it has a key length equal to the string length (in theory)
And the += operator was just an example of concatenation. If you are using char arrays then that wont concatenate, it'll give you weird characters since it's adding the ASCII values together.
The loop will keep going until it has a key length equal to the string length (in theory)
And the += operator was just an example of concatenation. If you are using char arrays then that wont concatenate, it'll give you weird characters since it's adding the ASCII values together.
Last edited by ShawnCplus; Dec 6th, 2007 at 5:40 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
OK, you originally wanted your key length to match your string length. To do that you need to keep repeating the key until it matches the length of the target string. This is why the outer loops has added to it the length of the key each time the loop iterates.
Last edited by ShawnCplus; Dec 6th, 2007 at 6:26 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
•
•
Join Date: Dec 2007
Posts: 10
Reputation:
Solved Threads: 0
•
•
•
•
OK, you originally wanted your key length to match your string length. To do that you need to keep repeating the key until it matches the length of the target string. This is why the outer loops has added to it the length of the key each time the loop iterates.
Many thanks
![]() |
Similar Threads
- Popups and problem loading desktop (Viruses, Spyware and other Nasties)
- Wireless connection problem with encryption. (Networking Hardware Configuration)
- problem please help im desperate (Networking Hardware Configuration)
- Yet another AURORA problem (Viruses, Spyware and other Nasties)
- Simple problem with encryption (Java)
- Need Help with a part of my encryption program PLEASE! (C#)
- help with/removing window's encryption on my data (Windows NT / 2000 / XP)
- File I/O Manipulation Prob (Java)
- WG602v2 connection problem (Networking Hardware Configuration)
Other Threads in the Java Forum
- Previous Thread: Gregorian Calender help
- Next Thread: Help with Idea?!?
| Thread Tools | Search this Thread |
-xlint add android api applet application array arrays automation bi binary blackberry bluetooth chat class classes client code compile compiler component converter database digit draw eclipse equation error event exception fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image input int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying oracle page pearl print problem program programming project qt recursion scanner screen server set size sms sort spamblocker sql string swing system thread threads time tree variablebinding windows xor







.