OpenVMS Source-Code Demos

base64_demo

1000	!=======================================================================
	! title  : base64_demo_100.bas
	! author : Neil Rieck
	! created: 2019-06-06
	! history:
	! ver who when   what
	! --- --- ------ -------------------------------------------------------
	! 100 NSR 190606 1. original effort
	!=======================================================================
	option type=explicit
	declare long i%, j%, fails
	declare string a,b,c
	external string function BASE64_ENCODE(string)
	external string function BASE64_DECODE(string)
	dim string p(9)
	!
	!	need some test phrases
	!
	p(1) =	"Its continuing mission: to explore strange new worlds, to seek out new life and new civilizations,"+	&
		"to boldly go where no one has gone before."
	p(2) =	"Its continuing mission: to explore strange new worlds, to seek out new life and new civilizations,"+	&
		cr+lf+													&
		"to boldly go where no one has gone before."
	p(3)=	"It was the dawn of the third age of mankind, ten years after the Earth/Minbari war."		+cr+lf+	&
		"The Babylon Project was a dream given form. Its goal: to prevent another war by creating"	+cr+lf+	&
		"a place where humans and aliens could work out their differences peacefully. It's a port"	+cr+lf+	&
		"of call, home away from home for diplomats, hustlers, entrepreneurs, and wanderers."		+cr+lf+	&
		"Humans and aliens wrapped in two million, five hundred thousand tons of spinning metal,"	+cr+lf+	&
		"all alone in the night. It can be a dangerous place, but it's our last best hope for peace."	+cr+lf+	&
		"This is the story of the last of the Babylon stations. The year is 2258. The name of the"	+cr+lf+	&
		"place is Babylon 5."
	!
	print "Test 1:"
	when error in								!
	    while 1								!
		read a								!
		print "test phrase   : ";a
		b = BASE64_ENCODE(a)
		print "base64 encoded: ";b
		c = BASE64_DECODE(b)
		print "base64 decoded: ";c
		if a = c then
			print "test result   : pass"
		else
			print "test result   : FAIL"
			fails = fails + 1
		end if
		print "===================="
	    next
	use
	    print "-i-status:";err
	end when
	sleep 1
	!
	print
	print "Test 2:"
	when error in
	    for i% = 1 to 26
		a = ""
		for j% = 1 to i%					!
		    a = a + chr$(64+j%)					! just upper-case characters
		next j%							!
		print "test phrase   : ";a
		b = BASE64_ENCODE(a)
		print "base64 encoded: ";b
		c = BASE64_DECODE(b)
		print "base64 decoded: ";c
		if a = c then
			print "test result   : pass"
		else
			print "test result   : FAIL"
			fails = fails + 1
		end if
		print "===================="
	    next i%
	use
	    print "-i-status:";err
	end when
	sleep 2
	!
	print
	print "Test 3:"
	when error in
	    for i% = 1 to 3				!
		a = p(i%)				!
		print "test phrase   : ";a
		b = BASE64_ENCODE(a)
		print "base64 encoded: ";b
		c = BASE64_DECODE(b)
		print "base64 decoded: ";c
		if a = c then
			print "test result   : pass"
		else
			print "test result   : FAIL"
			fails = fails + 1
		end if
		print "===================="
	    next i%
	use
	    print "-i-status:";err
	end when
	sleep 1
	print
	print "Test 4:"
	when error in
	    for i% = 1 to 256				!
		a = ""
		for j% = 0 to i%-1			!
		    a = a + chr$(j%)			!
		next j%					!
		print "test phrase   : non-printable characters"
		b = BASE64_ENCODE(a)
		c = BASE64_DECODE(b)
		if a = c then
			print "test result   : pass at step:";i%
		else
			print "test result   : FAIL at step:";i%
			fails = fails + 1
		end if
		print "===================="
	    next i%
	use
	    print "-i-status:";err
	end when
	sleep 1
	print "there were";fails;"failures"
	!
	goto fini
	!
	data	"M","Ma","Man","Man is distinguished"
	!
	!
32000	fini:
	end
	!
32010	%include "BASE64_ENCODE_100.FUN"
	!
32020	%include "BASE64_DECODE_100.FUN"
	!

left hand Back to OpenVMS
left hand Back to OpenVMS Demo Index
home Back to Home
Neil Rieck
Waterloo, Ontario, Canada.