From 8cd59bb944ed9373eb04420a32f3b7cfce0a8956 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 15 Mar 2014 15:13:35 +0100 Subject: better muc invitations. clearified the creation of ad hoc mucs with an alert dialog --- src/eu/siacs/conversations/utils/CryptoHelper.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/eu/siacs/conversations/utils') diff --git a/src/eu/siacs/conversations/utils/CryptoHelper.java b/src/eu/siacs/conversations/utils/CryptoHelper.java index ebbbd9674..550639d23 100644 --- a/src/eu/siacs/conversations/utils/CryptoHelper.java +++ b/src/eu/siacs/conversations/utils/CryptoHelper.java @@ -1,9 +1,14 @@ package eu.siacs.conversations.utils; +import java.security.SecureRandom; +import java.util.Random; + import android.util.Base64; public class CryptoHelper { final protected static char[] hexArray = "0123456789ABCDEF".toCharArray(); + final protected static char[] vowels = "aeiou".toCharArray(); + final protected static char[] consonants ="bcdfghjklmnpqrstvwxyz".toCharArray(); public static String bytesToHex(byte[] bytes) { char[] hexChars = new char[bytes.length * 2]; for ( int j = 0; j < bytes.length; j++ ) { @@ -31,4 +36,21 @@ public class CryptoHelper { return Base64.encodeToString(saslBytes, Base64.DEFAULT); } + + public static String randomMucName() { + Random random = new SecureRandom(); + return randomWord(3,random)+"."+randomWord(7,random); + } + + protected static String randomWord(int lenght,Random random) { + StringBuilder builder = new StringBuilder(lenght); + for(int i = 0; i < lenght; ++i) { + if (i % 2 == 0) { + builder.append(consonants[random.nextInt(consonants.length)]); + } else { + builder.append(vowels[random.nextInt(vowels.length)]); + } + } + return builder.toString(); + } } -- cgit v1.2.3