Results 1 to 15 of 15
  1. #1
    CodeX Pro is offline Member
    Join Date
    Dec 2012
    Posts
    32
    Rep Power
    0

    Default Doubt in converting

    Code has been updated. It is much more efficient know.

    Java Code:
    import java.util.Scanner;
    import java.util.HashMap;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    public class EnglishToLeetConverter {  
        
        private String toLeetCode(String str){ 
            Pattern pattern = Pattern.compile( "[^a-zA-Z]" );
            StringBuilder result=new StringBuilder();
            HashMap<Character, String> map = new HashMap<Character, String>();
            map.put('A', "@");
            map.put('B', "]3");
            map.put('C', "(");
            map.put('D', "|)");
            map.put('E', "€");
            map.put('F', "|=");
            map.put('G', "(_>");
            map.put('H', "|-|");
            map.put('I', "!");
            map.put('J', "_|");
            map.put('K', "|<");
            map.put('L', "|_");
            map.put('M', "|V|");
            map.put('N', "|V");
            map.put('O', "0");
            map.put('P', "|>");
            map.put('Q', "0_");
            map.put('R', "|2");
            map.put('S', "$");
            map.put('T', "7");
            map.put('U', "|_|");
            map.put('V', "\\/");
            map.put('W', "uJ");
            map.put('X', "><");
            map.put('Y', "¥");
            map.put('Z', "z");              
            
            for(int i=0;i<str.length();i++){
                char key=Character.toUpperCase(str.charAt(i));
                Matcher matcher = pattern.matcher(Character.toString(key));
                if(matcher.find()){
                    result.append(key); 
                }
                else{            
                result.append(map.get(key));
               }           
            }
            return result.toString();               
        }
        
        public static void main(String[] args){
            EnglishToLeetConvertor ob=new EnglishToLeetConvertor();
            Scanner scanner=new Scanner(System.in);
            System.out.println("Input English Words :- ");
            String engWord=scanner.nextLine();
            String leet=ob.toLeetCode(engWord);
            System.out.println("The 1337 Code is :- "+leet);
        }    
    }
    The above code converts an English text to 1337 language.

    But I want to know what can be done to do the vice versa that is from 1337 code to English text.

    Thank you
    Last edited by CodeX Pro; 05-07-2013 at 12:16 PM.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,360
    Blog Entries
    7
    Rep Power
    20

    Default Re: Doubt in converting

    Use another map that maps, say, "><" to "X" etc.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    JBelg is offline Member
    Join Date
    Oct 2012
    Posts
    36
    Rep Power
    0

    Default Re: Doubt in converting

    Unfortunately that wouldn't be possible. The letters in your 1337 vary from length, if all the letters were the same length (e.g. 2 characters to create 1 letter) you'd be able to create substrings and use a similar method as you already use.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,360
    Blog Entries
    7
    Rep Power
    20

    Default Re: Doubt in converting

    Quote Originally Posted by JBelg View Post
    Unfortunately that wouldn't be possible. The letters in your 1337 vary from length, if all the letters were the same length (e.g. 2 characters to create 1 letter) you'd be able to create substrings and use a similar method as you already use.
    Can't you use your imagination? First check two consecutive characters, next a single character; if nonen is in the reversed map, output the (single) character as is, otherwise output the found value. The mapping needs to be a bijection.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    JBelg is offline Member
    Join Date
    Oct 2012
    Posts
    36
    Rep Power
    0

    Default Re: Doubt in converting

    Quote Originally Posted by JosAH View Post
    Can't you use your imagination? First check two consecutive characters, next a single character; if nonen is in the reversed map, output the (single) character as is, otherwise output the found value. The mapping needs to be a bijection.

    kind regards,

    Jos
    You could do that, but if you look at L = |_ and U = |_| or M = |V| and N |V, there'd you already have a problem.
    I do realize I might have been a bit to harsh by saying it isn't possible, it could be perfectly possible, but changes would have to be made with the letters.

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,360
    Blog Entries
    7
    Rep Power
    20

    Default Re: Doubt in converting

    Quote Originally Posted by JBelg View Post
    You could do that, but if you look at L = |_ and U = |_| or M = |V| and N |V, there'd you already have a problem.
    I do realize I might have been a bit to harsh by saying it isn't possible, it could be perfectly possible, but changes would have to be made with the letters.
    Not really; try the longest prefix first (here it's three symbols/characters); but, as I wrote: the mapping needs to be a bijection, it doesn't need to be a prefix code (as a Huffman code).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    CodeX Pro is offline Member
    Join Date
    Dec 2012
    Posts
    32
    Rep Power
    0

    Default Re: Doubt in converting

    Quote Originally Posted by JosAH View Post
    Not really; try the longest prefix first (here it's three symbols/characters); but, as I wrote: the mapping needs to be a bijection, it doesn't need to be a prefix code (as a Huffman code).

    kind regards,

    Jos
    Cant there be some brute force method or String Pattern matching algorithm like Boyer-Moore or knuth-Morris-Pratt with which one can match the code and change it to english characters. Thank you for the feedback and it be great if you can try this and post some codes.

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,360
    Blog Entries
    7
    Rep Power
    20

    Default Re: Doubt in converting

    Quote Originally Posted by CodeX Pro View Post
    Cant there be some brute force method or String Pattern matching algorithm like Boyer-Moore or knuth-Morris-Pratt with which one can match the code and change it to english characters. Thank you for the feedback and it be great if you can try this and post some codes.
    Those algorithms aren't really needed here; construct a Map<String, Character> mapping from a 'leet speek' symbol (a String) to a single character. The following snippet finds a leet speak symbol as a prefix of a String text:

    Java Code:
    String find(String text) {
       for (int i= Math.min(3, text.length()); i >= 1; i--) {
          Character c= revMap.get(text.substring(0, i));
          if (c != null) return text.substring(0, i);
       }
       return null;
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    CodeX Pro is offline Member
    Join Date
    Dec 2012
    Posts
    32
    Rep Power
    0

    Default Re: Doubt in converting

    Quote Originally Posted by JosAH View Post
    Those algorithms aren't really needed here; construct a Map<String, Character> mapping from a 'leet speek' symbol (a String) to a single character. The following snippet finds a leet speak symbol as a prefix of a String text:

    Java Code:
    String find(String text) {
       for (int i= Math.min(3, text.length()); i >= 1; i--) {
          Character c= revMap.get(text.substring(0, i));
          if (c != null) return text.substring(0, i);
       }
       return null;
    }
    kind regards,

    Jos
    Thank I got it I will try this soon. Thank you.

  10. #10
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,411
    Rep Power
    5

    Default Re: Doubt in converting

    I don't think you can do it. Consider a pattern like |_|_|_| which could be UJJ or LLU. How would you disambiguate them? My assumption is that the reverse mapping of this encoding, whether grammatically sensible or not, is what is desired.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  11. #11
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,360
    Blog Entries
    7
    Rep Power
    20

    Default Re: Doubt in converting

    As I wrote already: the mapping needs to be a bijection, otherwise it can't be done.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,411
    Rep Power
    5

    Default Re: Doubt in converting

    As I read the thread, I know you said the mapping had to be a bijection. However, I had thought you had offered several ways of approaching it regardless. Hence my confusion.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  13. #13
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,360
    Blog Entries
    7
    Rep Power
    20

    Default Re: Doubt in converting

    Quote Originally Posted by jim829 View Post
    As I read the thread, I know you said the mapping had to be a bijection. However, I had thought you had offered several ways of approaching it regardless. Hence my confusion.

    Regards,
    Jim
    Mwah, I like to give little 'proofs by intimidation'; I could've added 'it is trivai that ...' ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  14. #14
    CodeX Pro is offline Member
    Join Date
    Dec 2012
    Posts
    32
    Rep Power
    0

    Default Re: Doubt in converting

    I think you'll should attempt this , I made a GUI for this too. If you want I can post it here. But I am looking forward to someone who will do the 1337 to English convertor. I will be obliged.

  15. #15
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,360
    Blog Entries
    7
    Rep Power
    20

    Default Re: Doubt in converting

    Quote Originally Posted by CodeX Pro View Post
    I think you'll should attempt this , I made a GUI for this too. If you want I can post it here. But I am looking forward to someone who will do the 1337 to English convertor. I will be obliged.
    Who? me? No thanks; it is your task anyway. I know the constraints, that's enough to yes or no attempt to implement it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 2
    Last Post: 12-08-2012, 04:32 AM
  2. have doubt
    By ras_pari in forum Advanced Java
    Replies: 3
    Last Post: 10-01-2009, 09:51 AM
  3. doubt
    By Chris555 in forum Networking
    Replies: 0
    Last Post: 08-05-2009, 02:58 PM
  4. Doubt
    By winkodes in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 12-20-2008, 08:34 PM
  5. doubt
    By shaju_inspira in forum Sun Java Wireless Toolkit
    Replies: 0
    Last Post: 01-18-2008, 08:38 AM

Posting Permissions

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