March 25, 2009

High level languages (don't) byte

My primary development language is Java, which is a pretty good high level language, in that it offers lots of useful features and expansive libraries even if it does take some of the finer control out of your hands.  It's even got some very handy libraries for arbitrarily-large integer and floating point math (i.e. BigInteger and BigDecimal).  All of that put together makes it a pretty handy language for doing math type stuff.

... or so you'd think.  Java lacks one crucial element for doing serious math/crypto work directly: the unsigned byte.  The thing java calls a byte contains signed values in the range from -128 to 127.  This is an amazingly frustrating thing to discover in the midst of attempting to implement any algorithm that requires real bit twiddling.  You can still do it, but you constantly have to work around the fact that you're working with a signed byte, and the fact that Java will refuse to assign it a value like 0xff.  The frustrating thing is that it wouldn't have been hard to add an unsigned byte to Java as a primitive type, but for some reason the Sun guys thought they could do without.  I managed do implement RSA in Java well enough, but I tired rather quickly of trying to do AES with it, and ended up going to MatLab.

Yeah, I know, copout on my part.  It was a class assignment, though, and the language chosen didn't matter, only that the steps were illustrated, and finding MatLab code for AES was trivial.  Next time, though, I'm ready.

public class Constants
{
public static final byte X_FF = -1;
public static final byte X_FE = -2;
public static final byte X_FD = -3;
public static final byte X_FC = -4;
public static final byte X_FB = -5;
public static final byte X_FA = -6;
public static final byte X_F9 = -7;
public static final byte X_F8 = -8;
public static final byte X_F7 = -9;
public static final byte X_F6 = -10;
public static final byte X_F5 = -11;
public static final byte X_F4 = -12;
public static final byte X_F3 = -13;
public static final byte X_F2 = -14;
public static final byte X_F1 = -15;
public static final byte X_F0 = -16;

public static final byte X_EF = -17;
public static final byte X_EE = -18;
public static final byte X_ED = -19;
public static final byte X_EC = -20;
public static final byte X_EB = -21;
public static final byte X_EA = -22;
public static final byte X_E9 = -23;
public static final byte X_E8 = -24;
public static final byte X_E7 = -25;
public static final byte X_E6 = -26;
public static final byte X_E5 = -27;
public static final byte X_E4 = -28;
public static final byte X_E3 = -29;
public static final byte X_E2 = -30;
public static final byte X_E1 = -31;
public static final byte X_E0 = -32;

public static final byte X_DF = -33;
public static final byte X_DE = -34;
public static final byte X_DD = -35;
public static final byte X_DC = -36;
public static final byte X_DB = -37;
public static final byte X_DA = -38;
public static final byte X_D9 = -39;
public static final byte X_D8 = -40;
public static final byte X_D7 = -41;
public static final byte X_D6 = -42;
public static final byte X_D5 = -43;
public static final byte X_D4 = -44;
public static final byte X_D3 = -45;
public static final byte X_D2 = -46;
public static final byte X_D1 = -47;
public static final byte X_D0 = -48;

public static final byte X_CF = -49;
public static final byte X_CE = -50;
public static final byte X_CD = -51;
public static final byte X_CC = -52;
public static final byte X_CB = -53;
public static final byte X_CA = -54;
public static final byte X_C9 = -55;
public static final byte X_C8 = -56;
public static final byte X_C7 = -57;
public static final byte X_C6 = -58;
public static final byte X_C5 = -59;
public static final byte X_C4 = -60;
public static final byte X_C3 = -61;
public static final byte X_C2 = -62;
public static final byte X_C1 = -63;
public static final byte X_C0 = -64;

public static final byte X_BF = -65;
public static final byte X_BE = -66;
public static final byte X_BD = -67;
public static final byte X_BC = -68;
public static final byte X_BB = -69;
public static final byte X_BA = -70;
public static final byte X_B9 = -71;
public static final byte X_B8 = -72;
public static final byte X_B7 = -73;
public static final byte X_B6 = -74;
public static final byte X_B5 = -75;
public static final byte X_B4 = -76;
public static final byte X_B3 = -77;
public static final byte X_B2 = -78;
public static final byte X_B1 = -79;
public static final byte X_B0 = -80;

public static final byte X_AF = -81;
public static final byte X_AE = -82;
public static final byte X_AD = -83;
public static final byte X_AC = -84;
public static final byte X_AB = -85;
public static final byte X_AA = -86;
public static final byte X_A9 = -87;
public static final byte X_A8 = -88;
public static final byte X_A7 = -89;
public static final byte X_A6 = -90;
public static final byte X_A5 = -91;
public static final byte X_A4 = -92;
public static final byte X_A3 = -93;
public static final byte X_A2 = -94;
public static final byte X_A1 = -95;
public static final byte X_A0 = -96;

public static final byte X_9F = -97;
public static final byte X_9E = -98;
public static final byte X_9D = -99;
public static final byte X_9C = -100;
public static final byte X_9B = -101;
public static final byte X_9A = -102;
public static final byte X_99 = -103;
public static final byte X_98 = -104;
public static final byte X_97 = -105;
public static final byte X_96 = -106;
public static final byte X_95 = -107;
public static final byte X_94 = -108;
public static final byte X_93 = -109;
public static final byte X_92 = -110;
public static final byte X_91 = -111;
public static final byte X_90 = -112;

public static final byte X_8F = -113;
public static final byte X_8E = -114;
public static final byte X_8D = -115;
public static final byte X_8C = -116;
public static final byte X_8B = -117;
public static final byte X_8A = -118;
public static final byte X_89 = -119;
public static final byte X_88 = -120;
public static final byte X_87 = -121;
public static final byte X_86 = -122;
public static final byte X_85 = -123;
public static final byte X_84 = -124;
public static final byte X_83 = -125;
public static final byte X_82 = -126;
public static final byte X_81 = -127;
public static final byte X_80 = -128;

}

package com.yourdomain;

import com.yourdomain.utils.Constants;

public class HexByte
extends Constants
{
private byte[] byteArray = new byte[] { X_FF, X_DE };

public static void main(String[] args)
{
}
}

Posted by: leoncaruthers at 08:33 AM | No Comments | Add Comment
Post contains 1197 words, total size 10 kb.

Comments are disabled. Post is locked.
20kb generated in CPU 0.08, elapsed 0.1081 seconds.
55 queries taking 0.0866 seconds, 99 records returned.
Powered by Minx 1.1.6c-pink.