[freenet-dev] Short refs was Re: alternative to #freenet-refs

Michael Rogers m.rogers at cs.ucl.ac.uk
Mon Dec 3 18:52:59 UTC 2007


Thanks! Here's the Java version of the poem generator (same dictionaries
as before).

Cheers,
Michael

Volodya wrote:
> Michael Rogers wrote:
>> Matthew Toseland wrote:
>>> Base32 this is 35 chars; the base32 may be easier, and is certainly shorter, 
>>> but this would be a nice option if you port the code to java. :)
>> Yeah, base32 would definitely be more practical but I just love the idea
>> of using random poetry to set up a darknet. :-) I'll have a crack at
>> porting it to Java when I get a minute.
>>
>> Cheers,
>> Michael
> 
> This is something to start with. It assumes to find the words in the "words-#.dic" files where # represents the
> order of the words... so its probably not as clean as you'd want it to be.
> 
> Also i think the problem would be with loading the file into the memory, when it will get large enough to be
> representing the true key i think you'll be having some serious out of memory issues.
> 
>                           - Volodya
> 
> 
> 
> ------------------------------------------------------------------------
> 
> import java.io.BufferedReader;
> import java.io.FileReader;
> 
> import java.io.FileNotFoundException;
> import java.io.IOException;
> 
> public class PoemKey {
> 	public static int WORDS_PER_KEY = 4;
> 	public static int BYTES_PER_WORD = 2;
> 	
> 	private static String[][] words;
> 	
> 	static
> 	{
> 		words = new String[WORDS_PER_KEY][];
> 		final int numOfWords = (int)Math.pow(2, BYTES_PER_WORD * 8);
> 		
> 		for(int i=0; i<WORDS_PER_KEY; i++)
> 		{
> 			words[i] = new String[numOfWords];
> 			try
> 			{
> 				BufferedReader fin = new BufferedReader(new FileReader("words-"+i+".dic"));
> 				for(int j=0; j < numOfWords; j++)
> 				{
> 					words[i][j] = fin.readLine();
> 				}
> 				fin.close();
> 			}
> 			catch(FileNotFoundException e)
> 			{
> 				//Well i don't really know what you'd want to do then.
> 			}
> 			catch(IOException e)
> 			{
> 				//Well i don't really know what you'd want to do then.
> 			}
> 		}
> 		
> 	}
> 	
> 	public static int[] poemToKey(String poem[])
> 	{
> 		int result[] = new int[WORDS_PER_KEY];
> 		
> 		return result;
> 	}
> 	
> 	public static String[] keyToPoem(int[] key)
> 	{
> 		String result[] = new String[WORDS_PER_KEY];
> 		
> 		for(int i=0; i<WORDS_PER_KEY; i++)
> 		{
> 			result[i] = words[i][key[i]];
> 		}
> 		
> 		return result;
> 	}
> 	
> 	public static void main(String args[])
> 	{
> 		int key[] = new int[WORDS_PER_KEY];
> 		
> 		System.out.print("The random key with "+WORDS_PER_KEY+" blocks "+BYTES_PER_WORD+" bytes each is: ");
> 		
> 		for(int i=0; i<WORDS_PER_KEY; i++)
> 		{
> 			key[i]=(int)(Math.random()*8*BYTES_PER_WORD);
> 			System.out.print(Integer.toHexString(key[i])+" ");
> 		}
> 		
> 		System.out.println("");
> 		
> 		System.out.print("The 'Poem' key is: ");
> 		String[] poem = keyToPoem(key);
> 		for(int i=0; i<WORDS_PER_KEY; i++)
> 		{
> 			System.out.print(poem[i]+" ");
> 		}
> 		System.out.println("");
> 	}
> }
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Devl mailing list
> Devl at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl

-------------- next part --------------
A non-text attachment was scrubbed...
Name: BasicEnglish.java
Type: text/x-java
Size: 1845 bytes
Desc: not available
Url : http://emu.freenetproject.org/pipermail/devl/attachments/20071203/6aedb03b/attachment.java 


More information about the Devl mailing list