#!/boot/home/config/bin/yab

doc Place a description of your
doc program here.
doc
doc Author, date, license

// set DEBUG = 1 to print out all messages on the console
DEBUG = 0

OpenWindow()

// Main Message Loop
dim msg$(1)
while(not leavingLoop)
	nCommands = token(message$, msg$(), "|")

	for everyCommand = 1 to nCommands
		if(DEBUG and msg$(everyCommand)<>"") print msg$(everyCommand)

		switch(msg$(everyCommand))
			case "_QuitRequested":
			case "MainWindow:_QuitRequested":
				leavingLoop = true
				break
			default:
				break
		end switch

	next everyCommand

wend

CloseWindow()

end


// Setup the main window here
sub OpenWindow()
	window open 100,100 to 600,500, "MainWindow", "Main Window"
	ausgabe$=system$("md5sum "+"/boot/home/ncursesKopie")
	print ausgabe$
	
	rem mit dem Text und Passwort funktioniert es nicht
rem t$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 1234567890 Das ist eine ganz schön komplizierte Sache."
 p$ = "efhVTENN;::54v54tjjj"

rem mit dem Text und Passwort funktioniert es
t$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 1234567890 Das ist eine ganz schön komplizierte Sache."
rem p$ = "3edc4rfv"


print "Text zum Verschluesseln: ", t$
print
print "Passwort zum Verschluesseln: ", p$
print

if (len(t$) / 2) <> (int(len(t$) / 2)) then
t$ = t$ + chr$(32)

endif

dim b3(len(t$) / 2)
dim b5(len(t$) / 2)

zaehler = 1
for i = 1 to len(t$) step 2
b1 = asc(mid$(t$, i, 1))
b2 = asc(mid$(t$, i + 1, 1))
b3(zaehler) = 256 * b1 + b2
zaehler = zaehler + 1
next i


rem --------------------------
rem hier wird verschlüsselt
rem --------------------------

for i = 1 to len(t$) / 2
for j = 1 to len(p$)
b3(i) = xor(b3(i), asc(mid$(p$, j, 1)) * 256)
next j
b5(i) = b3(i)
next i

d$ = ""
for i = 1 to len(t$) / 2
c1 = int(b5(i) / 256)
c2 = b5(i) - int(c1 * 256)
d$ = d$ + chr$(c1) + chr$(c2)
next i

print "Verschluesselter Text: ", d$
print

rem verschlüsseln beendet
rem --------------------------


rem --------------------------
rem hier wird entschlüsselt
rem --------------------------

dim b3(len(d$) / 2)
dim b5(len(d$) / 2)

zaehler = 1
for i = 1 to len(d$) step 2
b1 = asc(mid$(d$, i, 1))
b2 = asc(mid$(d$, i + 1, 1))
b3(zaehler) = (256 * b1) + b2
zaehler = zaehler + 1
next i

for i = 1 to len(t$) / 2
for j = len(p$) to 1 step -1
b3(i) = xor(b3(i), asc(mid$(p$, j, 1)) * 256)
next j
b5(i) = b3(i)
next i

s$ = ""
for i = 1 to len(t$) / 2
c1 = int(b5(i) / 256)
c2 = b5(i) - int(c1 * 256)
s$ = s$ + chr$(c1) + chr$(c2)
next i

print "Entschluesselter Text: ", s$
print

	
	
	
	return
end sub

// Close down the main window
sub CloseWindow()
	window close "MainWindow"
	return
end sub