Thursday, December 14, 2017

PC-2 Password Generator

So after the pyrrhic success with my PC-2 Enigma, I decided to repurpose a previous version for something else:  Password generator.

This version started out as an Enigma, but instead of needing an array to store the characters that I could us, I just used the ASCII character set 32-127.  Instead of looking up a value in an array, I could just do an "ASC" or "CHR$".  Much faster.

It had a big drawback, though.  Some of the characters in the table could not be input from the PC-2 keyboard.  So much for decrypting something.

But a password generator only needs to "encrypt".

1000 "V" clear: dim a$(1)*80: wait 0
1010 input "Start value:";r
1020 input a$(0)
1030 for i = 1 to len(a$(0))
1040 a= asc(mid$(a$(0),i,1))
1050 a=a-32+r
1060 if a > 95 LET a=a-96
1070 a=a+96/2
1080 if a > 95 LET a=a-96
1090 a=a+32
1095 :rem PC-2 chars not in standard ascii
1100 if a = 39 let a = 34
1110 if a = 91 let a = 123
1120 if a = 92 let a = 47
1130 if a = 93 let a = 125
1140 if a = 96 let a = 44
1150 if a = 127 let a = 32
1160 a$(1)=a$(1)+chr$ a
1170 r=r+1: if r >95 LET r=0
1180 cursor 0:print a$(1)
1190 next i
1200 wait: print a$(1)
1210 end

The only thing special was the 6 characters that the PC-2 uses that doesn't match up with the standard ASCII character set.  The PC-2 doesn't any single quotes (forward and back quotes).  It doesn't have "[" or "]" - instead it uses Yen and Square Root.  The "\" was some up-down square bracket that the PC-2 uses to denote an empty place in the string (sort of like a null).  And DEL was just like space.  So I convert those characters to something else.

This works much better and much faster.
So you enter something like "Tasty Cookies" and get "0>QSYa%RSPOL{" (start value of 12).
Given the same inputs, you will always get the same output.

I can say that the PC-2 is still useful today.

PC-2 encryption

So I decided to play some with programming my PC-2.  After much trials and tribulations (not to mention a nice long walk down memory lane re-learning how to program in BASIC), I was able to get the original project working.

The original idea was to make a version of the german Enigma working.  But that wasn't working out.  So I settled for something that had an encryption and decryption component.

The cypher is a simple polyalphabetic cypher with a rot-13 thrown in just for fun.

Text is limited to 80 chars (limitation of the PC-2) but since it takes so long to encrypt, I doubt anyone will hit that.

The aa() array is used so that we only encrypt to values that are enterable on the keyboard - otherwise we can’t enter the values to decrypt.

The main problem is that it's very slow.  I mean really slow.  *sigh*  It works, but the lack of speed makes it impractical.

DEF A - Encrypt text
DEF D - Decrypt text

10 "A" gosub 610:Wait 0
20 input a$(0)
30 for i = 1 to len(a$(0))
40 a= asc(mid$(a$(0),i,1)): gosub "L": a=e: gosub "F"
45 a$(1)=a$(1)+chr$ e
50 gosub "Z"
55 cursor 0:print a$(1)
60 next i
70 wait:print a$(1)
80 end

110 "D" gosub 610
120 input a$(0)
130 for i = 1 to len(a$(0))
140 a= asc(mid$(a$(0),i,1)): gosub "S": a=e: gosub "F"
145 a$(1)=a$(1)+chr$ e
150 gosub "Z"
160 next i
170 print a$(1)
180 end

200 :rem encrypt with current rotor value
210 "L" gosub 810:e=b+r
220 if e > 83 LET e=e-84
230 return

300 :rem decrypt with current rotor value
310 "S" gosub 810: e=b-r
320 if e < 0 LET e=e+84
330 return

400 :rem reflector
410 "F" e=a+84/2
420 if e > 83 LET e=e-84
430 e=aa(e):return

500 :rem rotate rotor
510 "Z" r=r+1: if r >83 LET r=0
520 return

600 : rem setup
610 clear: dim aa(83), a$(1)*80:restore
620 input “Start value:”;r
630 for i = 0 to 83: read aa(i): next i:return
640 DATA 32,33,35,36,37,38,40,41,42
650 DATA 43,44,45,46,47,48,49,50,51,52
660 DATA 53,54,55,56,57,58,59,60,61,62
670 DATA 63,64,65,66,67,68,69,70,71,72
680 DATA 73,74,75,76,77,78,79,80,81,82
690 DATA 83,84,85,86,87,88,89,90,94,97
700 DATA 98,99,100,101,102,103,104,105,106
710 DATA 107,108,109,110,111,112,113,114,115
720 DATA 116,117,118,119,120,121,122
730 return

800 :rem lookup
810 for ii =0 to 83: b = ii
820 if aa(ii)=a then return
830 next ii
840 return 0

Saturday, December 02, 2017

The end of "vacation"

So yesterday was my last "vacation" day.  I start work at a new job on Monday.  Which is a good thing because I finished up most of my projects.

The MemoSaver project was (finally) a success.  I had the expected issues with the serial interface, but I got it working at 1200 BPS.  At that speed, even with large memos, it works pretty well.

I finished up my Christmas Lights project.
150 NeoPixels hooked up to an Arduino Uno.  I powered it off a 5V 10A power supply.  Everything's protected with (laugh) a utility bucket with a tight fitting lid and some silicone sealant.

Still more projects in the queue, though.  I have a Fun Light Switch Box.  I made one of these before, but made some mistakes (partly due to a poor design and partly my ignorance).  They updated the design and I've learned, so this one should work out much better.

I have a couple of Matchbox restoration projects that are almost done.  Just waiting for parts now.

I want to write some meaty software for my PC-2.  So I'm looking at porting the Enigma (yes, the German WWII encryption machine) to my PC-2.  Since it's a complete rewrite from a modern programming language to a very constrained BASIC, I have to take it all the way down to basics and redesign things.  A nice, meaty, project.

The rest of my projects remain in hold status.  When I get time...  (Probably after I retire in 18 years.)