File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Languages and the fly likes C# problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "C# problem" Watch "C# problem" New topic
Author

C# problem

Oduche henry
Greenhorn

Joined: May 20, 2010
Posts: 2
good day all,
please I would be most grateful if anyone could help me with the code for a C# program that can read ordinary English text from a text file and encode it by replacing each text with the 13th next letter in the alphabet for example "Ang Rus" becomes "Nat Ehf" using the CryptoStream class i.e DES and TripleDES after which the encoded text is saved to a text file which can also be decoded also be decoded back to ordinary English using the same code.Thank you all
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38016
    
  22
Welcome to the Ranch

Please always tell us what your thread is about. No, we do not simply hand out code; show us what you already have and let us see what we think of it.
Oduche henry
Greenhorn

Joined: May 20, 2010
Posts: 2
hello everyone
this is what i have been able to do so far, but the problem i am faced with is that the loop does not seem to see all the "if" and else "if" statements it just executes the "else" statement at the end of the loop so all it ends up printing is the "from_file" therefore the text in the original text file "MyFile.txt" is exactly what is rewritten to the new file "MyFile1.txt" please i need help.
this is the source code:

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38016
    
  22


What a dreadful bank of "if"s. Are you really adding a constant amount to each char? You realise that at least in Java™, a char is an integer, so you can do arithmetic with it; you can add numbers, use the % operator for remainders, and add the remainder to 'a'. I am not sure whether it works in C#, but you should try it with some simple applications and see what happens.

Beware; if you get 'a' == 1 and add 1 to 'a' you will get 'b', so you may need an additional - 1. You may need to cast the result back to a (char) or use a method of Convert.
Lalit Mehra
Ranch Hand

Joined: Jun 08, 2010
Posts: 384

well as far as i remember it is possible to arithmetically compute chars in C# too ... so just try that and forget this bunch of if's ...

you could have used switch either buddy


http://plainoldjavaobject.blogspot.in
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38016
    
  22
We seem to agree about arithmetic on chars, but I don't think a switch-case-break block would have been any neater than all those ifs.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Also at line 22 you have

so none of those if-statements where you compare from_file to a single character is ever going to be true.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: C# problem
 
Similar Threads
Encode/Decode a String containing Chinese etc. characters to/from unicode
URLEncoding UTF text
Reading/Writing Foreign Text
[B&S] about US-ASCII encoding
Usage of inputTextarea in JSF