Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!216.196.98.144.MISMATCH!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.westnet.com.au!news.westnet.com.au.POSTED!not-for-mail NNTP-Posting-Date: Mon, 17 Oct 2011 22:19:15 -0500 From: "Qu0ll" Newsgroups: comp.lang.java.programmer References: In-Reply-To: Subject: Re: Simple alphanumeric "encryption"? Date: Tue, 18 Oct 2011 14:18:45 +1100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Newsreader: Microsoft Windows Live Mail 15.4.3538.513 X-MimeOLE: Produced By Microsoft MimeOLE V15.4.3538.513 Message-ID: Lines: 60 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 124.149.41.137 X-Trace: sv3-7dA+czDFSMaz09NUzqGtp3iSeiofdyKyW8eIVoWecheT5Hi234JdU9YgQ7oHsMOm0rNI//GEJwrqI8v!3WUykR72K44j52lt3vw5G2WWeGbZBtgmUK7YE1lQn13JZNck+0SccYBzCttRwLsc7SMdp9iGtrqE!Z/RSMNUN1sizAJ1fVvDdtw== X-Complaints-To: abuse@westnet.com.au X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3914 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8938 "Tom Anderson" wrote in message news:alpine.DEB.2.00.1110171515220.10855@urchin.earth.li... Sorry about the lack of indent... ------------------------------------------------------------------------------------------------ Oddly, i have a paper called "Ciphers with Arbitrary Finite Domains" sitting in my reading queue right not. You have at least two basic routes of attack here. First, recognise that alphanumerism is just an encoding of a general bit string. Decode the alphanumeric string into a bit string (by taking it as a base-36 or base-62 number, or whatever), encrypt that, then re-encode it. BigInteger has a constructor which takes a string and a radix, and a toString method which takes a radix. So: String s = "1sxjxyr5owpxwzmax6pyv1wgjpfuc4iadgrzhjpcameipq5sk"; BigInteger i = new BigInteger(s, 36); i = i.multiply(BigInteger.valueOf(2)); // this is a very poor kind of encryption System.out.println(i.toString(36)); BigInteger can also be converted to and from a byte[], which you can subject to proper encryption. You will need to be a bit careful, because conversion to an alphanumeric string will remove any leading zeroes, so you may need to pad. Also, the numbers may be negative, in which case the alphanumeric strings will have a leading minus sign. You might prefer to write your own conversion between bytes and digits, to avoid these problems. Note that using a proper cipher involves generating an initialisation vector (IV) for each message you encrypt, which you will then need to send along with the ciphertext. That's going to be slightly annoying, since the alphanumerically encoded IV is likely to be just as long as your message. Second, come up with a cipher that works directly on alphanumeric values, rather than bit strings, and apply that to your string. I don't think this is actually a terribly good idea, so i won't elaborate on it. ------------------------------------------------------------------------------------------------ OK, thanks Tom for that - the first option looks promising. I have 2 questions: Is there any significance in the choice of numbers 36 and 62? Can this simple method be adapted to handle input strings that contain spaces and also to preserve the case of the inputted characters? I forgot to mention this. -- And loving it, -Qu0ll (Rare, not extinct) _________________________________________________ Qu0llSixFour@gmail.com [Replace the "SixFour" with numbers to email me]