AlphaBot 26 sourcecode
Main Entry: AlphaBot System
Function: public class alphabotx
Description: The alphabotx class implements executable software code
which converts words (base 26+1) to their base-10 numerical equivalents and back.
Author: Baker, Baker & Baker
Year: 2000 2K / 2K2^4, H.MM Baker Baker Omnia Baker
Document date: OCT 2K2^3, MAY 2K2^4
/*
the xorart bignumber alphabot class
(alpha) versie notes (dutch)
Alphabot bewerkt de alphabetische input.
de alphabot class zoekt door spaties " " gemarkeerde karakter-reeksen; woorden.
Woorden kunnen behalve uit letters, ook uit cijfers en leestekens bestaan.
alle gevonden woorden worden karakter voor karakter bekeken en
de delen die alleen uit letters bestaan ('wordReals')
worden naar 26-tallige alphabotwoorden geconverteerd.
Cijfers en leestekens worden onveranderd meegegeven in de outputstream.
"b89" = "b" + "89" = 2 + 89 = 289
wordReals bestaan volledig uit letters en zijn dus altijd omkeerbaar:
"az" >> "53" >> "az"
"ba" >> "55" >> "ba"
Nb. in alphabot-26 komt "54" niet voor. // een ander soort hole
De conversie van cijfers is niet omkeerbaar in deze versie van alphabot:
"b3", een 'Unrealword', wordt 23, maar 23 terug wordt "w", niet "b3" // ....
"b3" >> "23" >> "w"
FIX...Laat alphabot de chunks in 'Unrealwords' taggen, waar deze %numeric of $alphabot zijn:
"de25b" >> "$113%25$2" >> "de25b" // nu omkeerbaar
below:
java code
*/
import java.math.*;
import java.io.*;
public class alphabotx {
//--- mainfunctie, 2 methods:
public static void main(String[] args) throws IOException {
String ourIntext = readSfile( "ascii.txt" ); // INPUT FILE: ASCII.TXT
String mysTapout = ""; // deze string collects alles voor de output
mysTapout += "\n The alphabotx class implements the executable program";
mysTapout += "\n in order to convert words to their base-10 numerical equivalents.";
mysTapout += "\n Baker Baker, Omnia Baker (2000)";
mysTapout += "\n ---------------------------------------------------------------------\n";
int ourIntextLen = ourIntext.length() -1; //fix last substr 4 use
BigInteger bimine = new BigInteger("0");
LookupWord myOOLookupWord = new LookupWord(bimine); // objectcode see below
String mywoord = "";
String mynonwoord = "";
String zonderboldzeroes = "";
String metboldzeroes = "";
int i = 0;
int b = 0;
String d = ourIntext.substring(0,1); // eerste substr
int u = myOOLookupWord.getLutidx(d); // returns -1 als geen letter
while ( i < ourIntextLen ) { // mainloop
mywoord = "";
metboldzeroes = "";
mynonwoord = mywoord; // i like this
// ===== OPT 1: NONWOORD
while ( u == -1 && i < ourIntextLen) {
mynonwoord += d;
i++;
d = ourIntext.substring(i, i+1); // 1 letter tegelijk
u = myOOLookupWord.getLutidx(d); // returns LUT-idx, of -1 als geen letter
}
mysTapout += mynonwoord;
// ===== OPT 2: WOORD
while ( u != -1 && i < ourIntextLen) {
mywoord += d;
i++;
d = ourIntext.substring(i, i+1); // 1 letter tegelijk
u = myOOLookupWord.getLutidx(d); // returns LUT-idx of -1 als geen letter
}
//
bimine = myOOLookupWord.getBigNumWord(mywoord); // convert 27dig to 10dig
zonderboldzeroes = bimine.toString();
//
for (b=0; b < zonderboldzeroes.length(); b++) {
if ( zonderboldzeroes.substring(b, b+1).equals("0") ){
metboldzeroes += "<B>" + zonderboldzeroes.substring(b, b+1) + "</B>";
} else {
metboldzeroes += zonderboldzeroes.substring(b, b+1); //default
}
}
//
mysTapout += metboldzeroes;
}
mysTapout += "\n\n...einde.\n";
String ourOuttext = writeSfile( "writtenout.txt" , mysTapout ); // OUTPUT
System.out.println(ourOuttext);
} // einde mainfunctie
//--- METHOD readSfile:
public static String readSfile(String f) {
String lineSep = System.getProperty("line.separator");
String allLinesstrg = "";
try {
String aLine = "";
BufferedReader br = new BufferedReader(new FileReader(f));
while(null != (aLine = br.readLine()))
allLinesstrg += aLine + lineSep;
br.close();
}
catch(Exception e) {
e.printStackTrace();
} finally {
return allLinesstrg;
}
}
//--- METHOD writeSfile
public static String writeSfile(String g, String mySdat) {
String tip="";
try {
BufferedWriter out = new BufferedWriter(new FileWriter(g));
out.write(mySdat);
out.close();
tip="\n\t no (io)exceptions \n";
}
catch(IOException e) {
tip="\n\t ohoh io exception! \n";
e.printStackTrace();
} finally {
return tip;
}
}
} // -------- eind class alphabotx --------
// LookupWord code:
class LookupWord extends alphabotx {
public BigInteger hjdb = new BigInteger("0");
// fill lookuptables:
public String[] radixLo =
{"leeg","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
public String[] radixUp =
{"LEEG","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
//--- CONSTRUCTOR
public LookupWord(BigInteger inzt) {
this.hjdb = inzt; // just any (BigInteger) to init obj?
}
//--- METHOD
public int getLutidx(String singlekarakt) {
// returns the [id] of one single char, as an int, eg z -> 26.
int li = 0;
int re = -1; // geen match
for (li=0; li < this.radixLo.length; li++) {
if ( singlekarakt.equals(this.radixUp[li]) || singlekarakt.equals(this.radixLo[li]) ){
re=li;
break;
}
}
return re; // 1-26 (A-Z); ...of -1, als geen match
}
//--- METHOD
public BigInteger getBigNumWord(String abcwoord) {
// returns Alphabot word as BI eg "ae"->32 , calls getLutidx() inside
String tletter = "";
int m = abcwoord.length();
int i = 0;
int j = m-1-i;
int u = 0;
long v = 0L;
BigInteger grondtal = new BigInteger("27"); // what radix u want
BigInteger bp = new BigInteger("0");
BigInteger bk = new BigInteger("0");
for (i=0; i<m; i++) {
tletter=abcwoord.substring(i, i+1);
u=this.getLutidx(tletter); // returns int ...
v=u; // ... int u need it long: v
bk = BigInteger.valueOf(v); // ... long v ... BigInteger bk ...
//bp = bp.add(bk.multiply(grondtal.pow(i))); // letters vlnr: i als exponent.
j = m-1-i;
bp = bp.add(bk.multiply(grondtal.pow(j))); // vrnl zoals NUMMERS; j=m-1-i; j als exponent
}
return bp; // returns a BigInteger
}
} // -------- eind class LookupWord --------