Mercurial > projects > dcrypt
changeset 31:f429c5e9dd69
hexDecode in dcrypt.misc.ByteConverter now converts all input to lowercase prior to processing.
author | Thomas Dixon <reikon@reikon.us> |
---|---|
date | Tue, 12 May 2009 17:10:47 -0400 |
parents | 21847420b1ac |
children | 2b4bccdc8387 |
files | dcrypt/misc/ByteConverter.d |
diffstat | 1 files changed, 13 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/dcrypt/misc/ByteConverter.d Mon May 11 15:32:00 2009 -0400 +++ b/dcrypt/misc/ByteConverter.d Tue May 12 17:10:47 2009 -0400 @@ -167,6 +167,7 @@ static ubyte[] hexDecode(string input) { + string inputAsLower = stringToLower(input); ubyte[] output = new ubyte[input.length>>1]; static ubyte[char] hexitIndex; @@ -175,10 +176,20 @@ for (int i = 0, j = 0; i < output.length; i++) { - output[i] = hexitIndex[input[j++]] << 4; - output[i] |= hexitIndex[input[j++]]; + output[i] = hexitIndex[inputAsLower[j++]] << 4; + output[i] |= hexitIndex[inputAsLower[j++]]; } return output; } + + private static string stringToLower(string input) + { + char[] output = new char[input.length]; + + foreach (int i, char c; input) + output[i] = ((c >= 'A' && c <= 'Z') ? c+32 : c); + + return cast(string)output; + } }