;Crypto›;›;Public-Key Cryptography›;For The Atari8.›;›;Author: Tom Hunt›;›;Date Created: 07.11.94›;›;Last Updated: 07.17.94›;›;(C) Copyright 1994›;All Rights Reserved›;CTH Enterprises›;›;Format of E/D Keys›;›;Byte 0=length byte, = 80›;Byte 1=rotations›;Byte 2=skip factor (<9)›;Byte 3=sub-prime length›;Byte 4=1st diget of sub-prime›;›;›;›INCLUDE "D3:rt2.act"›MODULE›INCLUDE "D3:real.act"›MODULE›INCLUDE "D3:prime.act"›MODULE››;››DEFINE max_bytes = "80"›››Byte Array Real_Key(max_bytes+1),› E_Key(max_bytes+1),› D_Key(max_bytes+1)›Byte Array key_path(65)›;›;›;         Ëåù Òåãïòä         ›;›;›;Format of KEY record.›;1 byte›Byte Key_Status›;40 bytes›Byte Array Key_Desc(45),› KR_E_Key(max_bytes+1),› KR_D_Key(max_bytes+1)›;›; ›;›Byte Array y_or_n(5),› fn="keys.dat"›;›Byte Array Matrix_1(40)›;›;Éîãìõäåó ôèáô òåñõéòå çìïâáìó›;›;›MODULE›INCLUDE "D3:MATRIX.ACT"›;›; ›;›Byte Func Get_Random()›byte wysync = $D49A›byte random = $D20A›byte i,r››r=255› wysync = 1› r = random› Do› wysync = 1› r = random›;Insure => '0 and <= 'F, hex.›; Until (r > $40 and r < $47) or (r > $2F and r < $3A)››;Insure => '0 and <= '9› Until (r > $2F and r < $3A)› Od›;Put(r)››;PrintE("Got a 6-bit ascii char")›return(r)›;›;›;›Proc Get_Desc()›;›;Gets the 40 byte text description›;from user.›;›byte x››PutE()›PrintE("Please input a 40 character or less")›PrintE("description of these keys.")›PutE()›PrintE("Examples: 'My personal keys.'")›PrintE(" 'Billy Bob's public key.'")›PutE()›;InputS(Key_Desc)›x = BGet(0,Key_Desc,40)›PutE()›Print("Is this correct? ÛÙ¯ÎÝ ")›InputS(y_or_n)›if y_or_n(1) = $9B then return fi›y_or_n(1) == &$DF›if y_or_n(1) = 'N then [$4C Get_Desc] fi›PutE()›return›;›;›;›Proc Embed(Byte Array Key,Sub_Prime)›;›;This routine generates the skip factor,›;and embeds it, the key, and the key-›;length into the E/D key.›;›; ›;Format of E/D Keys›;›;Byte 0=length byte, = 80›;Byte 1=rotations›;Byte 2=skip factor (<9)›;Byte 3=sub-prime length›;Byte 4=1st diget of sub-prime››byte i,b,c,d,e›;›;Get skip factor.›;Cannot allow a skip factor of 9.››b = 'A›while b > '8›do› b=Get_Random()› key(2) = b›od››Print("Skip factor = ")›Put(b):PutE()››b == -$30›c = Sub_Prime(0)›e = 1›for d = 4 to 80 step b›do› Key(d) = Sub_Prime(e)› e == +1› if e > Sub_Prime(0) then› exit› fi›od››;Save the length.›Key(3) = Sub_Prime(0) + $30›››return›;›; ›;›Proc Rotor_1(Byte Array key)›;key = 80 byte e/d key.›byte i,r,b,i2›››;PutE():PrintE("Before rotor1, key =")›;PrintE(key):PutE()››r = key(1)››for i=2 to 80›do› b = key(i)› for i2 = 0 to r› do› b == +1› if b > '9 then› b = '0› fi›› od› key(i) = b›od››;PrintE("After rotor1, key = ")›;PrintE(key):PutE()›;›;-------------------------›;Below is the decryption rotor.›;›;for i=2 to 80›;do›; b = key(i)›; for i2 = 0 to r›; do›; b == -1›; if b < '0 then›; b = '9›; fi›; od›; key(i) = b›;od››;PrintE("After restore, key = ")›;PrintE(key):PutE()›››return››;›; ›;›Proc Good_Exit()›Byte array answer(5)›Byte i›PutE()›Print ("Exit to DOS? ÛÙ¯ÎÝ ")›InputS(answer)›answer(1) == &$DF››If answer(1) = 'Y then›for i = 1 to 6›do› close(i)›od› [$A2$FF$9A$6C$0A$00] ;Reset Stack› ;JMP (DOSVec)›fi›return›;›;›Proc Get_Real_Key()›byte i,r››for i = 1 to max_bytes ›do› r = Get_Random()› Real_Key(i) = r›od›i==-1›Real_Key(0) = i›;Put(i)›return›;›;›;›Proc Get_KeyPath()›Byte i,i2››PutE():PutE()›PrintE("Please input the path of your keyring.")›PutE()›PrintE("Examples: 'D3:'")›PrintE(" 'D3:>keys>'")›PutE()››InputS(key_path)››If key_path(1) = $9B then return fi››PutE()›;Print(key_path)›Print("Are you sure? Ûù¯îÝ ")›InputS(y_or_n)›y_or_n(1) == &$DF››If y_or_n(1) = 'N then› [$4C Get_KeyPath]›Fi››for i = 1 to 8›;keys.dat›do› i2 = key_path(0) + i› key_path(i2) = fn(i)›od›i2 ==+1›key_path(i2) = $9B›key_path(0) = i2 ›;Print(">>")›;Print(key_path)›;Print("<<")››return›;›;›;›Proc Save_Keys()›byte i›;Get_KeyPath()›close(1)›Open_Append(1,key_path)›Key_Status = 1 ;1=active››for i = 0 to max_bytes›do› KR_E_Key(i) = E_Key(i)› KR_D_Key(i) = D_Key(i)›od››PutD(1,Key_Status)›Bput(1,Key_Desc+1,Key_Desc(0))›Bput(1,KR_E_Key+1,80)›Bput(1,KR_D_Key+1,80)››Close(1)›return›;›;›;›Proc Call_Prime()››byte b,i›;Get the length.›;Insure length > 4›b = 4››Print("Getting length, = ")›while b < 5 or b > 9›do› b=Get_Random()› b == -$30›od› Put(b+$30)›››A_Start(0) = b››PutE()››for i = 1 to b›do› b = Get_Random()› A_Start(i) = b›od››;Tidy up a bit.››While A_Start(1) = '0›do› b = Get_Random()› A_Start(1) = b›od›››If A_Start(0) = 9 then›;Insure < 199,999,990› A_Start(1) = '1›fi››If A_Start(0) = 5 then›;Insure > 65535› While A_Start(1) < '6› do› b = Get_Random()› A_Start(1) = b› od››› if A_Start(1) = '6 then› While A_Start(2) < '6› do› b = Get_Random()› A_Start(2) = b› od› fi›fi››PutE()›PrintE("The random sub-prime = ")›PrintE(A_Start)›;For i = 1 to A_Start(0)›;do›; b = A_Start(i) + $30›; put(b)›;od›PutE()››Prime()›PutE()›Print("The prime number = ")›PrintE(A_Prime)››PutE()››return››;›;›;›Proc Main()›byte i,key››Close(2)›Open_Read(2,"K:")››Poke(82,0)›Put('})›PrintE("")›PrintE("|ü Ãòùðôï®Ãïí          ü|")›PrintE("|ü ¨Ã© Ãïðùòéçèô ±¹¹´  ü|")›PrintE("|ü ÃÔÈ Åîôåòðòéóåó     ü|")›PrintE("|ü Áìì Òéçèôó Òåóåòöåä ü|")›PrintE("|ü Âù Ôïí Èõîô         ü|")›PrintE("")›PutE()››PrintE("Û°Ý Generate keys")›PrintE("Û±Ý Encode a message")›PrintE("Û²Ý Decode a message")›PrintE("Û³Ý Add key to key ring")›PrintE("Û´Ý Get key ring")›PrintE("ÛµÝ Display key ring")›PrintE("Û¶Ý Exit to DOS")›PutE()››;›key = GetD(2)›If key = '0 then› Get_Real_Key()› for i = 0 to max_bytes › do› E_Key(i) = Real_Key(i)› od›› Get_Real_Key()› for i = 0 to max_bytes› do› D_Key(i) = Real_Key(i)› od››› PrintE("Your public encryption and private")› PrintE("decryption keys have been created.")› PutE()››; PrintE("Do you want to view the ")›; Print ("keys? ÛÙ¯ÎÝ ")››; InputS(y_or_n)›; y_or_n(1) == &$DF›; if y_or_n(1) = 'Y then››; PrintE("Here is your public encryption key-")›; PrintB(E_key(0)):PutE()›; PrintE(E_Key)›;›; PrintE("Here is your secret decryption key-")›; PrintB(D_key(0)):PutE()›; PrintE(D_Key)››; fi› PutE()›› Call_Prime()››; Print("Press RETURN ")›; InputS(y_or_n)›› PrintE("Before embedding number, E-Key =")› PrintE(E_Key):PutE()›› Embed(E_Key,A_Start)› Rotor_1(E_Key)›; PrintE("Public E-Key =")›; PrintE(E_Key)›› PrintE("After embedding number , E_Key =")› PrintE(E_Key):PutE()›› PrintE("Before embedding number, D-Key =")› PrintE(D_Key):PutE()›› Embed(D_Key,A_Prime)› Rotor_1(D_Key)›; PrintE("Private D-Key =")›; PrintE(D_Key)›› PrintE("After embedding number , D_Key =")› PrintE(D_Key):PutE()›› Print("Press RETURN ")› InputS(y_or_n)››› Prep_Matrix()›Print("A_Prime = ")›PrintE(A_Prime)›PrintE("Matrix_1 =")›PrintE(Matrix_1)›PutE()›› PrintE("Do you want to add them to your")› Print ("keyring? ÛÙ¯ÎÝ ")›› InputS(y_or_n)› y_or_n(1) == &$DF› if y_or_n(1) = 'Y then› ;› Get_KeyPath()› Save_Keys()›› fi›ElseIf key = '6 then› Good_Exit()››fi›[$4C main]›Return›››