codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Encryption problem! Help!  Lumiere at 08:59 on Friday, July 22, 2005
 

I am currently doing some encryption part of a cipher. The length of the ciphertext(encrypted text) is supposed to of the same length of the plaintext(original text). However, the ciphertext that I get is very long. I am using a textfile to contain the plaintext. Below is main code the for the read file and encryption part:

try {
input = new FileInputStream("/forum/input.txt");
bin = new BufferedInputStream(input);

int buffer;
int i = 0;

while((buffer = bin.read()) != -1) {
long l = (int)buffer;

long ciphertext = l ^ keystream;
String str = Long.toString(ciphertext);
for ( int x = 0; x < str.length(); ++x ) {
char ascii = str.charAt(x);
int y = (int) ascii;
System.out.print(y);
}
System.out.println();

if(i < 15)
{i++;}
else
{i = 0;}
}
} catch(Exception ex) {ex.printStackTrace();}

I am using string to get the plaintext and then convert it to long. I am using long so that I can perform the XOR operation with the keystream(in long[]).

Someone please help!!! I am running out of ideas on this >__<


  Re: Encryption problem! Help!  javabits at 18:44 on Tuesday, August 02, 2005
 

Your inner loop seems to be running from the beginning to the end of the string on each character being read from the buffer in the outer loop.

semper fi...

  Re: Encryption problem! Help!  Lumiere at 02:32 on Wednesday, August 03, 2005
 

I had managed to solve this problem by converting the keystream into 1 string and use substring to extract the bits that I want. Then, I convert back into their decimal values and perform XOR operation








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Finding File Size and Creating Error log
•  Ajax example: online chat
•  Re: Nested Javascripts
•  ISP says linefeeds are causing problems
•  Linker Error Unresolved External Borland Builder 2006
•  Have multiple ASP.NET web projects share pages and controls
•  Re: How can I read ASCII data file in C++
•  Trouble writing programs
•  Validation Problem


Recent Articles
What is a pointer in C?
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net


© Copyright codetoad.com 2001-2006