#!/usr/bin/perl
use strict;

my @orig;

#### belegte codes
$orig[7] = 200;
$orig[8] = 41;
$orig[9] = 10;
$orig[10] = 107;
$orig[11] = 76;
$orig[12] = 173;
$orig[13] = 142;
$orig[14] = 239;
$orig[15] = 192;
$orig[16] = 50;
$orig[17] = 19;
$orig[18] = 116;
$orig[19] = 85;
$orig[20] = 182;
$orig[21] = 151;
$orig[22] = 248;
$orig[23] = 217;
$orig[24] = 58;
$orig[25] = 27;
$orig[26] = 124;
$orig[27] = 93;
$orig[28] = 190;
$orig[29] = 159;
$orig[30] = 240;
$orig[31] = 34;

sub calc_next($){
	my $val = shift;

	if( ($val & 0x0f) == 0 ){
		$val ^= 0x11;
	}

	$val += 0x61;

	# korrigiere Überlauf in Bit 4 wg. 8bit Rechnung
	if( ($val & 0x0f) == 0 ){
		$val -= 0x10;
	}

	if( ($val & 0x20) == 0 ){
		$val -= 0x80;	# -6-2
	}

	$val &= 0xff;

	return $val;
}

sub print_val($$){
	my $exp = shift;
	my $val = shift;
	printf "\t%s%3d(%08b)", (($val & 0xff) == ($exp & 0xff)) ? '! ' : '? ', $val, $val & 0xff;
}


for my $i (8...31){	# gesicherte Codes
	my $base = $orig[$i-1];
	my $exp  = $orig[$i];

	my $val = calc_next($base);
	my $check = $val == $exp ? "OK" : "ERROR";
	printf "%2d->%2d: %3d/%08b->%3d/%08b: %3d/%08b: %s", $i-1, $i, $base, $base, $exp, $exp, $val, $val, $check;
	print "\n";
}

