2

I am searching for some encryption/decryption alghorithm which gives me only capital letters and without special characters (+,/,=). I've used DES algorithm and Rijndael (AES) algorithm, but both of those gave me special characters and mixed uppercase and lowercase characters.

I need readable licence to create since it will be much easier for me and for my clients to understand it when they need it.

Please, let me know if you need more information I can give you.

Hoh
  • 1,196
  • 1
  • 12
  • 30
  • please specify what you want, not how you are trying to implement it (see also [xy-Problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)). you say you want to implement some kind of licensing. what do you want to encrypt there, and what do you need this special string with only capital letters for? – codeling Jan 10 '14 at 11:43
  • 3
    Encrypt however you like then base32 encode the output which will encode to a string comprising 0-9A-Z http://stackoverflow.com/questions/641361/base32-decoding – Alex K. Jan 10 '14 at 11:47
  • @RandolphCarter I am trying to encrypt a string (date + couple of numbers + customerId). It's much easier when I am talking to my client and I am dictating him licence key so he can easily understand what I am telling him, otherwise there could be some mistakes and reading licence key with special characters and upper and lowercase letters can last forever. – Hoh Jan 10 '14 at 11:51
  • As per fejesjoco's reply, you can do your own encryption/encoding, unless your customers are unusually adept and also motivated to attempt to crack it. AES etc etc are overkill. (Or email them the key instead of phoning them) – peterG Jan 10 '14 at 11:58
  • The thing is that I am using this method so I can easily phone them since some of them have no internet connection @peterG Otherwise I am using online web service which checks for licence online. – Hoh Jan 10 '14 at 12:02
  • @Nidzaaaa ok fair enough. But you can probably do stuff with XOR, substitution, no-carry arithmetic, the random number generator etc that defeats the average punter. You're (presumably) not up against NSA/GCHQ – peterG Jan 10 '14 at 12:06
  • Well I have figured out that the only thing I should do is encrypt what I want, then Encode to Base32/Base64 and when I want to read it I have to Decode it first and then Decrypt... Should be easy work, we'll see... @peterG I am doing this for my company bussines so I am not trying to break to some US systems or whatever :) – Hoh Jan 10 '14 at 12:08
  • @Nidzaaaa - Well exactly! so it doesn't have to be *that* good :-) We do a very similar thing to what you're attempting and have never had a problem. In our case we we end up with a string of 20 digits, which we then format as four groups of five. Very easy to pass over the phone. – peterG Jan 10 '14 at 12:10
  • @peterG the thing is that I am one of junior developers in my company, so I am looking for a thing where I can prove myself to others :) Ambition is huge, but there is some lack of knowledge :) – Hoh Jan 10 '14 at 12:15
  • Trying to prove yourself with cryptography (or information security in general) is unfortunately not a good idea, because even teams of professionals who have been doing this for 20 years don't always get it right. The problem is that unlike other kinds of code, you won't know whether you've done it correctly or not until all is lost. Somebody clever once said that "programming crypto is like arming a bomb"... – ntoskrnl Jan 10 '14 at 13:57
  • @ntoskrnl Whilst you're 100% right, I'd just mention that in the context of the OP's question, it's a bit beside the point. He said it's for licensing, and some users aren't connected to the internet. So his biggest problem is what's to stop his end users just winding the system clock back, not making the encryption super-secure. – peterG Jan 10 '14 at 19:41
  • Nidzaaaa - just a nit, Rijndael is not AES (but AES is Rijndael). AES has only one block size of 128-bits; Rijndael allows 128-, 192- and 256-bit block sizes. – jww Jan 11 '14 at 09:34

2 Answers2

5

Encryptions are always binary. You can encode that binary data as a string, for example, in Base64. That does contain lower case letters and some special characters.

Base64 uses 64 characters, hence the name. That is 6 bits of information (2^6). But you need to encode 8 bit bytes. So what Base64 does is take 3 bytes from the input (3*8=24 bits), and convert that to 4 characters (4*6=24 bits).

What you need to do differently is that you have a smaller character set. There are 26 capital letters. I suggest you find 6 more acceptable characters, and then you get 5 bits per character (2^5=32). Or use only 16 characters, that is 4 bits per character (2^5=16).

That reminds me, 4 bits per character is hexadecimal encoding basically. So here's the easiest solution. Convert your binary data to hexadecimal, then you get 0..9 and A..F characters. Then change 0..9 to G..P. And now you have a string that only contains letters A to P. You can even skip capital O or I to make it even less confusing.

You can find binary to hexa conversion and vice versa anywhere, also here on SO. You can do the character mapping with a properly filled Dictionary<char, char> (sorry, I'm a C# guy, don't know what it's called in VB).

fejesjoco
  • 11,763
  • 3
  • 35
  • 65
  • So, as I figured out I have to get my key I get from (let's say) DES algorythm and then to encode it to Base64, right? I am getting a key like this 'hswBjBa8OBgermiFNX/Cfc36LsuZoMSaS2ILbNmo23g='. That's the key I get when I'm using DES alg. I just want to get something readable out of this, since this could be really painfull to read to someone. – Hoh Jan 10 '14 at 12:41
  • I don't know what exactly gives you Base64, but you don't need that, you need the raw binary array, and then convert that to a hexadecimal string. – fejesjoco Jan 10 '14 at 12:45
  • This might be a stupid question, but how can I convert the key I gave you (DES) to raw binary array? I'm trying to make this working properly (to become readable) for like 2 weeks til now... – Hoh Jan 10 '14 at 12:46
  • Where did you get that key in the first place? You never mentioned that. To convert from/to base64, you can use Convert.From/ToBase64String. – fejesjoco Jan 10 '14 at 13:12
  • That key is actualy ClientID+couple of numbers+Date encrypted using DES algorythm – Hoh Jan 10 '14 at 14:01
  • Yes you mentioned DES algorithm but not the name of the class/framework/library that gave you that base64 encoded string. Believe me, when a DES key is born, it is binary, a series of bytes. Something converted it to base64. – fejesjoco Jan 10 '14 at 14:08
  • You need more upvotes. I used this solution to provide unambigious encrypted keys to my customer by first running them through encryption and then this process. I love it! – Josh Jun 06 '19 at 19:49
1

I am searching for some encryption/decryption alghorithm which gives me only capital letters and without special characters (+,/,=).

Take a look at Base26 Encoding.

I am trying to encrypt a string (date + couple of numbers + customerId).

This is kind of interesting because the input alphabet in almost all numbers. If you could format it such that its all numbers, then you could try a small-space Format Preserving Encryption (FPE) scheme.

Modern PFEs are built on block ciphers and include tweaks. Take a look at Phillip Rogaway's A Synopsis of Format-Preserving Encryption for an introduction.

jww
  • 97,681
  • 90
  • 411
  • 885