Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should really consider using a <a href="http://docs.oracle.com/javase/6/docs/api/java/util/Map.html" rel="nofollow"><code>Map</code></a> to store character/encoding pairs. Oh, and to create these random pairs you can add your characters to a <code>List</code> and make use of <a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Collections.html#shuffle%28java.util.List%29" rel="nofollow"><code>Collections.shuffle</code></a> instead of reinventing the wheel yourself.</p> <hr> <p>Let me demonstrate using only <code>Lalpha</code> (only lowercase letters). You want something along these lines:</p> <pre><code>List&lt;Character&gt; l = new ArrayList&lt;Character&gt;(Lalpha.length); for (char c : Lalpha) l.add(c); Collections.shuffle(l); Map&lt;Character, Character&gt; encoding = new HashMap&lt;Character, Character&gt;(Lalpha.length); Map&lt;Character, Character&gt; decoding = new HashMap&lt;Character, Character&gt;(Lalpha.length); for (int i = 0 ; i &lt; Lalpha.length ; i++) { encoding.put(Lalpha[i], l.get(i)); decoding.put(l.get(i), Lalpha[i]); } </code></pre> <p>Now lets say we wanted to encode / decode the string <code>helloworld</code>, we would do this:</p> <pre><code>String s = "helloworld"; // Encode: String enc = ""; for (char c : s.toCharArray()) enc += encoding.get(c); System.out.println(enc); // Decode: String dec = ""; for (char c : enc.toCharArray()) dec += decoding.get(c); System.out.println(dec); </code></pre> <p>Output (one of many possible):</p> <blockquote> <p>vjwwmtmcwz<br> helloworld</p> </blockquote> <p>Of course, you can incorporate uppercase letters and what-not using the same idea.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload