Results 1 to 10 of 10
- 09-12-2012, 01:22 PM #1
Member
- Join Date
- Sep 2012
- Location
- Navi Mumbai
- Posts
- 30
- Rep Power
- 0
How to Scramble text in a text file?'
Hello frnz....'
'
Is there any code in java by which the contents of the text file are scrambled and saved to a new text file...'
For e.g.
If textfile "new.txt" contains text as "abcdefghijklmnopqrstuvwxyz";
Then, the output of new file "edited.txt" should be any scrambled text like "alskdjfhgpqowieurytmznxbcv";
'
Thanx in advance....'
'
'
- 09-12-2012, 02:24 PM #2
Re: How to Scramble text in a text file?'
Please see my response on your other thread: Any Component to input Image???"
Much the same advice applies here (except the bit about the Swing tutorial -- you need to go through the starting pages of the same tutorials).
Further, I recommend that you go through How to ask questions the smart way and apply what you learn there, or you're never going to get meaningful help on this or any other forum.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 09-12-2012, 02:28 PM #3
Senior Member
- Join Date
- Oct 2011
- Location
- Sweden
- Posts
- 123
- Rep Power
- 0
Re: How to Scramble text in a text file?'
Hi suyog53,
from what I know, there are no classes or methods in the Java standard library that can do what you want. Though, it can easily be achieved with some simple coding.
Read in your file as a StringBuilder.
Create a method with preferably a for-loop.
Generate random numbers with the Random class from java.util. Use these random numbers to get chars in your StringBuilder object, and switch them using suitable code.
It would be something like this:
I think you can figure out the rest!Java Code:StringBuilder sb = new StringBuilder(string s); Random rf = new Random(); for(i = 0; i < 1000; i++){ sb.setCharAt(rf.nextInt(sb.length),sb.charAt(rf.nextInt(sb.length))); }
Cheers,
Z!
- 09-12-2012, 02:29 PM #4
Re: How to Scramble text in a text file?'
You could convert the String to an array, then to a list, then shuffle the list, then convert to an array and create a String from the array. You'll need to read the API doc to see what classes and methods to use.
If you don't understand my response, don't ignore it, ask a question.
- 09-13-2012, 08:18 AM #5
Member
- Join Date
- Sep 2012
- Location
- Navi Mumbai
- Posts
- 30
- Rep Power
- 0
Re: How to Scramble text in a text file?'
@zyril........................'
nice 1...'
but, once you scramble it using random logic as you suggested,
again unscrambling to original text is not achieved....'
'
I need to scramble and unscramble the text'
so, random logic cannot be used...'
- 09-13-2012, 08:20 AM #6
Member
- Join Date
- Sep 2012
- Location
- Navi Mumbai
- Posts
- 30
- Rep Power
- 0
Re: How to Scramble text in a text file?'
@ Norm....I got ur idea............'
But it is still difficult to create such a code'
Can you explain it with code????'
Thanx........'
- 09-13-2012, 11:16 AM #7
Senior Member
- Join Date
- Oct 2011
- Location
- Sweden
- Posts
- 123
- Rep Power
- 0
Re: How to Scramble text in a text file?'
If so, you don't want to scramble it, you want to encrypt it in a simple way? Scramble for me is just spreading things out in an irregular order that cannot be reversed.
Look into text encryption in Java.
- 09-13-2012, 11:38 AM #8
Re: How to Scramble text in a text file?'
You have already been told, in Any Component to input Image???" (which you didn't have the courtesy to reply to)
What didn't you understand about the two bits of advice? Or are you under the impression that you are free to misuse the forum as you like?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 09-14-2012, 08:36 AM #9
Member
- Join Date
- Sep 2012
- Location
- Navi Mumbai
- Posts
- 30
- Rep Power
- 0
Re: How to Scramble text in a text file?'
@zyril'
I am currently working on project where:
------------------------------------------------------------------------------------------------------------------------------
• Image file -------------converted to------------> Numeric text file (text file containing pixel values in numbers)' ◘
• Numeric text file -------------replaced to--------------> Alphabet text file (1 replaced wit 'A', 2 with 'B'...)' ◘
• Alphabet text file -------------encrypted to------------> Encrypted text file ('A' encrypted with 'T', 'B' with 'U'...)' ◘
• Encrypted text -------------scrambled to------------> New text file (Text in text file scrambled using a logic)' ◘
-------------------------------------------------------------------------------------------------------------------------------
The above part is of Encryption'
So, during decryption, the process is reversed, for which i need to unscramble the text again'
I have completed first three parts.......(Conversion. Replacement & Encryption)'
But, stuck on Scrambling part'
Hope you got my problem.....'
- 09-14-2012, 08:37 AM #10
Member
- Join Date
- Sep 2012
- Location
- Navi Mumbai
- Posts
- 30
- Rep Power
- 0
Similar Threads
-
Reading from a text file, then writing back to Text Area in Reverse
By medic642 in forum New To JavaReplies: 8Last Post: 07-17-2011, 02:38 PM -
Transforming xml to text keeps placing blank line at beginning of text file
By DerekRaimann in forum Advanced JavaReplies: 7Last Post: 03-05-2011, 09:25 AM -
Applet program to open a text file and display the content in text area
By bitse in forum Java AppletsReplies: 0Last Post: 12-09-2010, 05:56 PM -
textfield - printstream - text file - to much text
By keneid in forum New To JavaReplies: 2Last Post: 06-14-2010, 10:18 AM -
Insert text records from text file into a DB
By nicedad in forum JDBCReplies: 8Last Post: 11-06-2009, 06:52 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks