Results 1 to 10 of 10
  1. #1
    suyog53 is offline Member
    Join Date
    Sep 2012
    Location
    Navi Mumbai
    Posts
    30
    Rep Power
    0

    Smile 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....''
    '

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default 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.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    124
    Rep Power
    0

    Default 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:


    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)));
    }
    I think you can figure out the rest!

    Cheers,
    Z!

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default 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.

  5. #5
    suyog53 is offline Member
    Join Date
    Sep 2012
    Location
    Navi Mumbai
    Posts
    30
    Rep Power
    0

    Default 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...'

  6. #6
    suyog53 is offline Member
    Join Date
    Sep 2012
    Location
    Navi Mumbai
    Posts
    30
    Rep Power
    0

    Default 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........'

  7. #7
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    124
    Rep Power
    0

    Default 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.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: How to Scramble text in a text file?'

    Quote Originally Posted by suyog53 View Post
    @ Norm....I got ur idea............'
    But it is still difficult to create such a code'
    Can you explain it with code????'
    Thanx........'
    You have already been told, in Any Component to input Image???" (which you didn't have the courtesy to reply to)
    Quote Originally Posted by DarrylBurke View Post
    This is a technical forum, not a chatroom. Please spell words in full.
    ...
    No, this is a forum, not a code factory.
    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?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    suyog53 is offline Member
    Join Date
    Sep 2012
    Location
    Navi Mumbai
    Posts
    30
    Rep Power
    0

    Question 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.....'

  10. #10
    suyog53 is offline Member
    Join Date
    Sep 2012
    Location
    Navi Mumbai
    Posts
    30
    Rep Power
    0

    Default Re: How to Scramble text in a text file?'

    @darry..............'
    k'
    i'll take care of that things............'

Similar Threads

  1. Replies: 8
    Last Post: 07-17-2011, 03:38 PM
  2. Replies: 7
    Last Post: 03-05-2011, 10:25 AM
  3. Replies: 0
    Last Post: 12-09-2010, 06:56 PM
  4. Replies: 2
    Last Post: 06-14-2010, 11:18 AM
  5. Replies: 8
    Last Post: 11-06-2009, 07:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •