Alyce
Oct 14, 2006
- "Reverted to Oct 9, 2006 7:07 am: restoring submission instructions"
Submit Articles Here for Liberty BASIC Programmer's Encyclopedia
Anybody can submit articles to the Liberty BASIC Programmer's Encyclopedia. You do not need to be a member of Wikispaces or of this site.
License
By adding content to the Liberty BASIC Programmer's Encyclopedia, you are bound by the license. If you do not want to release your work under this license, do not submit articles. Click HERE to read the License.
Article Guidelines
The Liberty BASIC Programmer's Encyclopedia is a place for full-length technical articles. Authors should make sure that articles are well-structured, that words are spelled correctly, and that all code works properly. Click HERE for help on technical writing.
Adding Articles
- Click the edit button at the top of this page.
- Add your article to the list at the bottom of this page by typing a name for your page inside of double square brackets. If your article is called "Using Arrays", your link would look like this: * [[Using Arrays]]
- Save the editing of this page.
- View this page and click on the link you just created.
- On the new page, click the edit link and type or paste your article.
- Please place your name and the date at the top of your article, along with a descriptive title.
- Save your edits. That's all there is to it!
Editing Articles
To learn how to use WikiText markup to edit site content, click HERE. You don't need to know WikiText, though. When you are editing a page, there is a button near the bottom to "Use Visual Editor." If you want to try some editing in a safe place where you can do no harm, play in the Test Area . Before finalizing the article, you can click the "Preview" button to see how your article will appear, and make changes as needed.
Additional Files
If your article requires images or other additional files, simply upload them and include links in your article. When you are editing a page there is a link in the upper right for "Images". Click this to view a list of all available files and images.
Article Placement
One of the organizers of the Liberty
Confirmation
Organizers of the Liberty BASIC Programmer's Encyclopedia will make any modifications they feel are needed. Authors may accept or reject these changes before articles are listed in
Article Modification in
One of the advantages of this format is that
LIST ARTICLES HERE
- Scientific precision - by
ones and zeroes in your key mix all the bits successively with several iterations in such a way that at the end nobody should be able toform the original 64 bit orderGrahame King - ADDED TO NUMBERS AND MATH -
Alyce Aug 24, 2006 - copying,moving,deleting and renaming files - by
looking at it or working at it without knowing the key.The more bits you have in your key the more complex it gets. The idea is to make it so complex and costly in computer time and effort that it must be unfeasible to find it at a reasonable time like few hours, days, weeks or years. Number of bits in the key is known as key length.However, you must not confuse the key lengths of block ciphers like DES, 3DES, IDEA or AES with public key ciphers like RSA, Diffie Helman, etc. 128 bit 3DES ( Triple DES ) has equivalent strength to 2048 bit RSA. So, if someone claims that he has a super 512 bit cipher based on state of the RSA which is much better than strong 128 bit ciphers, you should take this as an entertainment. This is like comparing apples and oranges. Key size should be considered in the context of algorithm. As a general rule 112 bit to 256 bit block ciphers can be considered pretty strong and unbreakable. Number theoric public key alogrithms like RSA must have 1024 or more bits. In fact for public key lengths, estimated secure key lengths are givenAlex Barfoot - added to Using Files, Windows API -
Alyce Aug 28, 2006 - Listview, trapping double click - by
years. Currently it must be equal to or more than 1024 bits butEldron Gill - Tagged byyear 2010 you should raise it to 2048 bits and beyond. We will discuss public key cryptography and RSA on the next article.DES : DATA ENCRYPTION STANDARDThe most widely used encryption system in the world is DES: Data Encryption Standard adopted in 1977 by US government.DES is designed by IBM engineers for call in 1973 for the US government request for an encryption system for all unclasssified government data.It is based on an earlier cipher system called LUCIFER and was the only system acceptable by the US National Security Agency (NSA). Originally designed as a 128-bit system, under the advise of NSA it was reduced to 56-bits. There has been significant controversy over this reduction which NSA claims that it was made due to hardware design reasons while oppenents say this significantly reduced the strength of the algorithm to a level so that it can be easily broken by NSA.Nevertheless, DES has been widely adopted by many sectors but mainly by the financial sector which has decided to use it for the protection of PIN numbers on ATMs and EFT/POS terminals. It is also used for encrypt sensitive data on host to host communications, checking for message integrity with a special mode of DES called cipher block chaining.DES is a block cipher operating on 64 bit data blocks (8 bytes) using 56 bit keys implementing succesfully the following concepts:Diffusion: the statistical structure of cleartext data is mapped into a long range statistics of ciphertext. This means that every clear to cipher text transformation affects significantly following transformations making statistical frequency analysis efforts unfeasibleConfusion: makes the relationship between ciphertext and the key very complex to make discovery of the key extremely difficult.Avalanche Effect: assures big changes in ciphertext with even 1 bit change in the key.DES algorithm has 16 rounds with a specific S-box scheduling substitutions, shifting and shuffling bits with permutations with a resultant avalanche effect so huge that it the statistical relation between the cleartext and ciphertext becomes impossible at the end.DES is effectively employing the techniques of substitutions and transpositions in a very systematic and foolproof way.DES design have classified secrets such as the nature of S-boxes. Why are those numbers are used ? These questions were never answered but only said that those are indeed very good numbers, arbitrary change of these number could result in significant security losses. This is to say, these numbers are so designed that they are optimizing the bit shuffling in such a way to make sure no trace of original data can be deduced from the output without knowing the key.DES is asymetric cipherso using the same key for both encryption and decryption. To decrypt the algorithm is executed in reverse to obtain the cleartext .Therefore, the encyrptor and decryptor must share a common secret key.Algorithm is public but key is secret. If the key become known than all of the encrypted data can be decrypted.This brings following significant problems:- Key Generation- Key Distribution- Key Exchange- Key Protection- Key VerificationWe will discuss these problems on the next article before talking about public key algorithms like RSA which is solving these problems.I believe this sufficient overview of DES in these introductory articles. Those readers who want to go deeper can find many articles on Internet or several books in their bookstores. So, let’s go directly into an example implementation of DES written purely in Liberty Basic.REM'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''DES ENCRYPTION / DECRYPTION DEMO SOFTWARE WRITTEN PURELY IN LIBERTY BASIC'Copyright(c) 2006, Verisoft CryptoMan'www.verisoft.com onur@verisoft.com'----------------------------------------------------------------------------------------------'This software and source code is provided for educational private use and may not be used'for commercial purposes without express written consent of VERISOFT.'----------------------------------------------------------------------------------------------'LIABILITY CLAUSE:'Verisoft will not accept any liabilities or claims due to use, non-use, misuse of this software'or damages to property or life under any circumstances, direct or indirect. Use it at your own'risk. There are no claims to performance, correctness and fitness of this software.'Use of or exportation of cryptographic software to certain countries; and disclosure thereof'may violate local laws and regulations.'-----------------------------------------------------------------------------------------------' LESSON 1: : THIS EXAMPLE ONLY ENCRYPTS AND DECRYPTS PLAINTEXT FILES' DES : IT IS NOT FAST, IT IS NOT PERFECT, IT IS NOT COMPLETE !' SYMETRIC CRYPTO : IT ONLY SHOWS, HOW REAL ANSI/ISO DATA ENCRYPTION STANDARD' : WORKS: SINGLE DES, 56-BIT KEYS, ECB MODE.'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''WARNING: IF YOU ENCRYPT AND IMPORTANT FILE, AND THEN ERASE IT, AND THEN FORGET THE KEY' AND YOU HAVE ONLY ENCRYPTED FILE; YOU WILL BE IN TROUBLE. PLEASE, DON'T CALL' US OR ANYONE. IF YOU HAVE GOOD FRIENDS AT NSA, THEY MAY DO SOMETHING BUT' NOT US. SORRY. DON'T ENCRYPT YOUR IMPORTANT FILES AND FORGET YOUR KEY !!!!!!!!'_______________________________________________________________________________________________GLOBAL INITIALTR$,FINALTR$,SWAP$,KEYTR1$,KEYTR2$,ETR$,PTR$,CR$,LF$CALL InitializeNoMainWinWindowWidth = 800WindowHeight = 500UpperLeftX=int((DisplayWidth-WindowWidth)/2)UpperLeftY=int((DisplayHeight-WindowHeight)/2)statictext #main.statictext6, "Source File", 15, 2, 108, 20statictext #main.statictext7, "Destination File", 15, 57, 192, 20statictext #main.statictext8, "Encryption Key", 15, 112, 200, 20textbox #main.source, 15, 24, 280, 25button #main.browseSource, "Browse", [browseSource], UL, 230, 2, 60, 20textbox #main.destination, 15, 80, 280, 25button #main.browseDestination, "Browse", [browseDestination], UL, 230, 57, 60, 20textbox #main.key, 15, 132, 110, 25radiobutton #main.selectDecrypt, "Decrypt Source to Destination", [selectDecrypt], [reset], 15, 192, 280, 25radiobutton #main.selectEncrypt, "Encrypt Source to Destination", [selectEncrypt], [reset], 15, 172, 280, 25button #main.go, "Go", [go], UL, 10, 222, 85, 25texteditor #main.tesrc, 300,10, 490, 200 'The handle for our texteditor is #window.tetexteditor #main.tedes, 300,230,490, 200 'The handle for our texteditor is #window.tegraphicbox #main.gb, 800, 1, 10, 10open "DES Crypto Demo V1.00"+space$(80)+"Verisoft(c)2006, www.verisoft.com " for window as #mainprint #main, "font Courier 10"print #main, "trapclose [quit]"MODE = 1#main.selectEncrypt, "set"wait[browseSource] 'Search for source filefiledialog "Select source file:","*.*",INFILE$if INFILE$ <> "" then #main.source, INFILE$wait[browseDestination] 'Search for destination filefiledialog "Select destination file:","*.*",OUTFILE$if OUTFILE$ <> "" then #main.destination, OUTFILE$wait[selectDecrypt] 'Set mode to decryptionMODE = 2wait[selectEncrypt] 'Set mode to encryptionMODE = 1wait[reset] 'Perform action for the radiobutton named 'selectDecrypt'wait[go] 'Do it!#main.key, "!contents? KEY$"#main.source, "!contents? INFILE$"#main.destination, "!contents? OUTFILE$"cursor hourglassRESULT = ENCRYPTION(MODE,INFILE$,OUTFILE$,KEY$)cursor normalif RESULT = 1 then notice "DES Crypto Result"+CR$+"Action completed successfully"if RESULT = 2 then notice "Encrypt/decrypt mode not properly selected"if RESULT = 3 then notice "Source file does not exist"if RESULT = 4 then notice "Destination file already exists"if RESULT = 5 then notice "No de/encryption key specified"wait[quit] 'End the programclose #mainendfunction ENCRYPTION(MODE,INFILE$,OUTFILE$,KEY$)IF MODE=1 THENOPEN INFILE$ FOR INPUT AS #1IF OUTFILE$="" THEN OUTFILE$="ENCTEMP";TIME$("ms");".TXT"OPEN OUTFILE$ FOR OUTPUT AS #2#main.tesrc,""#main.tesrc,DATE$();" ";TIME$()#main.tesrc,"----------------------------------------------"#main.tedes,""#main.tedes,DATE$();" ";TIME$()#main.tedes,"----------------------------------------------"WHILE EOF(#1)=0LINE INPUT #1,TEXT$TEXT$=TEXT$+CR$#main.tesrc,TEXT$;DO'''''''''''''''''''''''PAD WITH NUL WHEN BLOCK LESS THAN 8 BYTES''''''''''''''''''''DX$=LEFT$(TEXT$,8)PDX$=chr$(0)+chr$(0)+chr$(0)+chr$(0)+chr$(0)+chr$(0)+chr$(0)+chr$(0)PDX$=DX$+LEFT$(PDX$,8-LEN(DX$))ENC$=DESencrypt$(PDX$,KEY$)HX$=SpecHex$(ENC$)#main.tedes,HX$PRINT #2,HX$TEXT$=MID$(TEXT$,9)SCANLOOP WHILE LEN(TEXT$)>0WENDCLOSE #1CLOSE #2#main.tesrc,"----------------------------------------------"#main.tedes,"----------------------------------------------"ENCRYPTION = 1ELSEOPEN INFILE$ FOR INPUT AS #1IF OUTFILE$="" THEN OUTFILE$="DECTEMP";TIME$("ms");".TXT"OPEN OUTFILE$ FOR OUTPUT AS #2#main.tesrc,""#main.tesrc,DATE$();" ";TIME$()#main.tesrc,"----------------------------------------------"#main.tedes,""#main.tedes,DATE$();" ";TIME$()#main.tedes,"----------------------------------------------"WHILE EOF(#1)=0LINE INPUT #1,TEXT$#main.tesrc,TEXT$DX$=PackHex$(LEFT$(TEXT$,16))DEC$=DESdecrypt$(DX$,KEY$)'''''''''''''''''REMOVE PADDING ADDED DURING ENCRYPTION''''''''''''''''''''''TDEC$=""FOR I=1 TO 8CH$=MID$(DEC$,I,1)IF CH$>CHR$(0) THEN TDEC$=TDEC$+CH$NEXT#main.tedes,TDEC$;PRINT #2,TDEC$;WENDCLOSE #1CLOSE #2#main.tesrc,"----------------------------------------------"#main.tedes,"----------------------------------------------"ENCRYPTION = 1END IFend functionEND''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' COPY GLOBALS AND ALL BELOW THIS LINE UNDER YOUR SOFTWARE AND YOU WILL DESencrypt AND' DESdecrypt FUNCTIONS IN YOUR SOFTWARE.' DES WORKS WITH 8 BYTE KEYS ON 8 BYTE DATA. IT ENCRYPTS TO 8 BYTE BLOCK AND WILL' DECRYPT FROM 8 BYTE BLOCK TO PLAIN TEXT. IF YOU HAVE LONGER DATA THEN YOU MUST' DIVIDE IT INTO 8 BYTE BLOCKS. SHORTER THAN 8 BYTE BLOCKS MUST BE PADDED AND UNPADDED' BY YOUR SOFTWARE LOGIC. ABOVE, DEMO SHELL SHOWS THIS NICELY. HOWEVER, DOWN BELOW' THE GUI SHELL, IT CALLS THE FUNCTIONS BELOW. DES NEEDS ALL THOSE COMPLEX FUNCTIONS' AND NUMBERS. YOU SHOULD NOT TOUCH OR WORRY ABOUT THEM. JUST USE DESencrypt( DATA$,KEY$)' OR DESdecrypt( ENCDATA$,KEY$ ). YOU CAN DECRYPT WITH THE EXACT SAME KEY YOU USED FOR' ENCRYPTION.''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Function PackHex$( y$ )z$=""for j=1 to len(y$) step 2n=HEXDEC(mid$(y$,j,2))z$=z$+chr$(n)next jPackHex$=z$end functionFUNCTION SpecHex$( y$ )z$=""FOR j=1 TO LEN(y$)n=ASC(MID$(y$,j,1))IF n<16 THEN z$=z$+"0"z$=z$+DECHEX$(n)NEXT jSpecHex$=z$END FUNCTIONFUNCTION RANDOMKEY$()X$=""FOR I=1 TO 8X$=X$+CHR$(RND(1)*255)NEXT IRANDOMKEY$=X$END FUNCTIONSUB InitializeCR$=CHR$(13):LF$=CHR$(10)INITIALTR$=""DATA 58,50,42,34,26,18,10,2,60,52,44,36,28,20,12,4,62,54,46,38,30,22,14,6,64,56,48,40,32,24,16,8,57,49,41,33,25,17,9,1,59,51,43,35,27,19,11,3,61,53,45,37,29,21,13,5,63,55,47,39,31,23,15,7FOR I=1 TO 64:READ X:INITIALTR$=INITIALTR$+CHR$(X): NEXT IFINALTR$=""DATA 40,8,48,16,56,24,64,32,39,7,47,15,55,23,63,31,38,6,46,14,54,22,62,30,37,5,45,13,53,21,61,29,36,4,44,12,52,20,60,28,35,3,43,11,51,19,59,27,34,2,42,10,50,18,58,26,33,1,41,9,49,17,57,25FOR I=1 TO 64:READ X:FINALTR$=FINALTR$+CHR$(X): NEXT ISWAP$=""DATA 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32FOR I=1 TO 64:READ X:SWAP$=SWAP$+CHR$(X): NEXT IKEYTR1$=""DATA 57,49,41,33,25,17,9,1,58,50,42,34,26,18,10,2,59,51,43,35,27,19,11,3,60,52,44,36,63,55,47,39,31,23,15,7,62,54,46,38,30,22,14,6,61,53,45,37,29,21,13,5,28,20,12,4,0,0,0,0,0,0,0,0FOR I=1 TO 64:READ X:KEYTR1$=KEYTR1$+CHR$(X): NEXT IKEYTR2$=""DATA 14,17,11,24,1,5,3,28,15,6,21,10,23,19,12,4,26,8,16,7,27,20,13,2,41,52,31,37,47,55,30,40,51,45,33,48,44,49,39,56,34,53,46,42,50,36,29,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0FOR I=1 TO 64:READ X:KEYTR2$=KEYTR2$+CHR$(X): NEXT IETR$=""DATA 32,1,2,3,4,5,4,5,6,7,8,9, 8,9,10,11,12,13,12,13,14,15,16,17,16,17,18,19,20,21,20,21,22,23,24,25,24,25,26,27,28,29,28,29,30,31,32,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0FOR I=1 TO 64:READ X:ETR$=ETR$+CHR$(X): NEXT IPTR$=""DATA 16,7,20,21,29,12,28,17,1,15,23,26,5,18,31,10,2,8,24,14,32,27,3,9,19,13,30,6,22,11,4,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0FOR I=1 TO 64:READ X:PTR$=PTR$+CHR$(X): NEXT IDIM ROTS(16)DATA 1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1FOR I=1 TO 16:READ X:ROTS(I)=X: NEXT IDIM S(8,64)DATA 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5,-
JanetTerra Oct 9, 0, 7,_0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,_4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,_15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13DATA 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,_3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,_0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,_13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9DATA 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,_13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,_13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,_1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12DATA 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,_13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,_10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,_3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14DATA 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,_14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,_4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,_11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3DATA 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,_10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,_9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,_4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13DATA 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,_13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,_1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,_6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12DATA 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,_1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,_7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,_2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11FOR I=1 TO 8FOR J=1 TO 64READ XS(I,J)=XNEXT JNEXT IEND SUBSUB TRANSPOSE BYREF DAT$, T$, NDIM iDAT(64),iT(64),iX(64)FOR I=1 TO 64IF MID$(DAT$,I,1)=CHR$(1) THEN iDAT(I)=1 ELSE iDAT(I)=0iX(I)=iDAT(I)iT(I)=ASC(MID$(T$,I,1))NEXTFOR I=1 TO NiDAT(I)=iX( iT(I) )NEXTZAT$=""FOR I=1 TO 64: ZAT$=ZAT$+CHR$(iDAT(I)): NEXT IDAT$=LEFT$(ZAT$ ,64)END SUBSUB ROTATE BYREF KEY$X$=LEFT$(KEY$,56)X$=MID$(X$,2,55)X$=LEFT$(X$,27)+LEFT$(KEY$,1)+MID$(X$,29)X$=LEFT$(X$,55)+MID$(KEY$,29,1 )KEY$=LEFT$(X$,56)END SUBSUB UNROTATE BYREF KEY$X$=LEFT$(KEY$,56)X$=MID$(KEY$,28,1)+LEFT$(X$,55)X$=LEFT$(X$,28)+MID$(KEY$,56,1)+MID$(X$,30)KEY$=LEFT$(X$,56)END SUBSUB F I, BYREF KEY$, BYREF A$, BYREF X$DIM Z(64),Y(64)E$=LEFT$(A$,56)CALL TRANSPOSE E$,ETR$, 48FOR J=1 TO ROTS(I)CALL ROTATE KEY$NEXTIKEY$=LEFT$(KEY$,56)CALL TRANSPOSE IKEY$,KEYTR2$, 48FOR J=1 TO 48IF ASC(MID$(E$,J,1))+ASC(MID$(IKEY$,J,1))=1 THEN Y(J)=1 ELSE Y(J)=0NEXTFOR K=1 TO 64: Z(K)=ASC(MID$(X$,K,1)): NEXTFOR K=1 TO 8R=32*Y(6*K-5)+16*Y(6*K)+8*Y(6*K-4)+4*Y(6*K-3)+2*Y(6*K-2)+Y(6*K-1)+1IF ODD(S(K,R) / 8) THEN Z(4*K-3)=1 ELSE Z(4*K-3)=0IF ODD(S(K,R) / 4) THEN Z(4*K-2)=1 ELSE Z(4*K-2)=0IF ODD(S(K,R) / 2) THEN Z(4*K-1)=1 ELSE Z(4*K-1)=0IF ODD(S(K,R)) THEN Z(4*K) =1 ELSE Z(4*K) =0NEXTX$=""FOR K=1 TO 64: X$=X$+CHR$(Z(K)): NEXTCALL TRANSPOSE X$,PTR$,32END SUBSUB F2 I, BYREF KEY$, BYREF A$, BYREF X$DIM Z(64),Y(64)E$=LEFT$(A$,64)CALL TRANSPOSE E$, ETR$, 48IKEY$=LEFT$(KEY$,64)CALL TRANSPOSE IKEY$, KEYTR2$ , 48FOR J=1 TO 48IF ASC(MID$(E$,J,1))+ASC(MID$(IKEY$,J,1))=1 THEN Y(J)=1 ELSE Y(J)=0NEXT JFOR J=1 TO ROTS(17-I)CALL UNROTATE KEY$NEXT JFOR K=1 TO 64: Z(K)=ASC(MID$(X$,K,1)): NEXTFOR K=1 TO 8R=32*Y(6*K-5)+16*Y(6*K)+8*Y(6*K-4)+4*Y(6*K-3)+2*Y(6*K-2)+Y(6*K-1)+1IF ODD(S(K,R) / 8) THEN Z(4*K-3)=1 ELSE Z(4*K-3)=0IF ODD(S(K,R) / 4) THEN Z(4*K-2)=1 ELSE Z(4*K-2)=0IF ODD(S(K,R) / 2) THEN Z(4*K-1)=1 ELSE Z(4*K-1)=0IF ODD (S(K,R)) THEN Z(4*K)=1 ELSE Z(4*K)=0NEXTX$=""FOR K=1 TO 64: X$=X$+CHR$(Z(K)): NEXTCALL TRANSPOSE X$,PTR$,32END SUBFUNCTION ODD( N )IF INT(N) MOD 2 = 0 THEN ODD=0 ELSE ODD=1END FUNCTIONFUNCTION DESencrypt$( PTEXT$, KY$ )PLAINTEXT$=BINARY$(PTEXT$)KEY$=BINARY$(KY$)A$=LEFT$( PLAINTEXT$,64 )CALL TRANSPOSE A$, INITIALTR$ ,64CALL TRANSPOSE KEY$, KEYTR1$ ,56FOR I=1 TO 16B$=LEFT$( A$,64 )A$=MID$(B$,33,32)CALL F I,KEY$,A$,X$FOR J=1 TO 32IF ASC(MID$(B$,J,1))+ASC(MID$(X$,J,1))=1 THEN A$=A$+CHR$(1) ELSE A$=A$+CHR$(0)NEXTNEXTCALL TRANSPOSE A$,SWAP$,64CALL TRANSPOSE A$,FINALTR$,64DESencrypt$=ASCII$(A$)END FUNCTIONFUNCTION DESdecrypt$( CTEXT$, KY$ )CRYPTEXT$=BINARY$(CTEXT$)KEY$=BINARY$(KY$)A$=LEFT$( CRYPTEXT$,64 )CALL TRANSPOSE A$, INITIALTR$ ,64CALL TRANSPOSE KEY$, KEYTR1$ ,56FOR I=1 TO 16B$=LEFT$( A$,64 )A$=MID$(B$,33,32)CALL F2 I,KEY$,A$,X$FOR J=1 TO 32IF ASC(MID$(B$,J,1))+ASC(MID$(X$,J,1))=1 THEN A$=A$+CHR$(1) ELSE A$=A$+CHR$(0)NEXTNEXTCALL TRANSPOSE A$,SWAP$,64CALL TRANSPOSE A$,FINALTR$,64DESdecrypt$=ASCII$(A$)END FUNCTIONFUNCTION BINARY$( BMP$ )BITMAP$=""FOR j=1 TO 8L1=ASC(MID$(BMP$,j,1))FOR i=7 TO 0 STEP -1IF ( 2^i AND L1 ) THEN BITMAP$=BITMAP$+CHR$(1) ELSE BITMAP$=BITMAP$+CHR$(0)NEXT iNEXT jBINARY$=BITMAP$END FUNCTIONFUNCTION ASCII$( BMP$ )BITMAP$=""C=0N=7FOR j=1 TO 64C=C+ASC(MID$(BMP$,j,1))*2^NN=N-1IF ( j MOD 8 )=0 THENBITMAP$=BITMAP$+CHR$(C)N=7C=0END IFNEXT jASCII$=BITMAP$END FUNCTION56 BITS DES KEY LENGTHYou may wonder why 56 bits used instead of 64 bits. This because every byte has 7 databits and 1 parity bit, so 8 x 7 = 56 bits is the effective key size. Highest parity bitis generally ignored but if it is checked it is expected that DES keys must have odd parity.3DES: TRIPLE DES56 bits DES also known as single DES has been cracked for few years now. This can be donewith specially designed parallel computers with high speed hardware DES crypto processors.Another method used is network effort made with tens of thousands of Pentium PCs connectedover Internet. Using a special screensaver which uses idle time of these PCs to search akey space assigned to each PC. This way, every PC is given a different key space from amaster computer. After several days or months eventually one of the PCs finds the key andreports this to the master computer via Internet. This attack is possible if a known plaintextattack is possible. Otherwise this sort of brute force attack is difficult. However, mostattractive target financial encrypted data such as enciphered PIN numbers have a knownplaintext pattern and thus such an attack is possible. Due to this all credit card systemsare now changed to 3DES:TRIPLE DES.TRIPLE DES: uses two 56 bit DES keys in what is known as EDE mode: Encrypt Decrypt Encryptmode. So, effectively it is 112 bit encryption but generally termed as 128 bit encryption.So, this is the so called strong 128 bit encryption, single DES run three times withtwo keys. Ofcourse, you can also use 3 keys in EEE mode with three keys but the classic3DES is 112 bit 3DES which encrypts with EDE and decrypts with DED using two 56 bit keys.3DES very strong and we can say it is unbreakable until quantum computers can be builtfeasibly. Otherwise, even with the fastest of fastest computers in the world the 112 bitskey space can not be feasibly searched with brute force trial and error method until findingall the right bits. There are 2 to the power 112 different possible keys. This is a big number.How big ? Let's say if every bit can be represented by one electron which is not possible butstill we say if this is possible and to store every possible than you will have5 192 296 858 534 827 628 530 496 329 220 096 electrons x 112 bits.1 electron is 1/1837 weight of an AMU, atomic mass unit. 1 gram is equivalent to 1,675,000,000,000,000,000,000,000 AMU.According to this the weight of our data only in our hard disk will be 188,996 kg ( 416,292 lb) or almost 200 metrictons. Which is to say you will have pretty heavy metal on your desktop. Not a good idea toput this data in your laptop. In fact according to current hard disk technology your harddisk will instantly turn into a black hole and suck up everything around if you try tostore all 3DES keys possible. So, don't mess around with 3DES without adult supervision.MAC : MESSAGE AUTHENTICATION CODEOne of the useful applications of DES or 3DES is MAC: Message Authentication Code whichis used for INTEGRITY while DES/3DES is used for CONFIDENTIALITY. This means, using MAC,you can create a digital signature to assure no part of the message, even one bit havebeen changed in transit. For example, if you are making a wire transfer from accountnumber 1029121 to 2771099 for $125.00 you will not someone messing around with datato divert the funds to account no 2499911 instead of 2771099 or change amount oftransfer to $12500.00. Hence, between two banks they exchange MAC'ing keys to beused for transfers and then they sign each transfer by dividing the transfer messageinto 8 byte blocks and successively encrypt each block with DES or 3DES, XOR the nextblock to the encrypted value of previous block until end of the message. Finally, youget a 8 byte hexadecimal value. Usually you take the left half 4 bytes and call thisthe MAC of the message. You append this MAC to the end of each message. Finally thereceipient gets the message and MAC after which the receiver recomputes the MAC againusing the agreed key and compares the transmitted MAC. If two MACs don't match thiswill mean somebody messed with data in transit. Ofcourse the same can be applied tofiles stored on the disk, you can put a MAC at the end of each line of a criticalcontract and one MAC for the entire document. If document MAC doesn't match to expectedMAC then you can check every line with Line MACs to see which line of the documentwas altered. Likewise, you can put MACs to every accounting record to detect aninternal fraud of an employee messing with company accounts. MAC is the backboneof many financial transactions like credit card systems. For example the latestEMV chip cards from Visa and Mastercard or Contactless cards like Mastercard PayPassor Visa Wave uses variants of MAC like CVV, ARQC, ARPC, etc to provide end to endmessage integrity of credit and debit card transactions. From the date, time,amount, currency code, card number and random elements ARQC Authorisation RequestCryptogram is generated by the chip card in a POS or ATM during transaction whichis checked by the issuer bank online and if it is good a corresponding ARPC AuthorisationResponse Cryptogram is sent back to the terminal which submits this code to the cardand finally the card decide whether this response is bona fide and accepts or rejectsthe completion succesfully or declination of the transaction. All of this happens ina few seconds around the globe and using a smartcard with a chip smaller than1 millimeter square and lately with contacless cards wirelessly over the air.So, these things are not science fiction but real life behind the scenes thingsof everyday events like checking out from the supermarket with your credit cardor using your digital mobile phone.CONCLUSIONSo you have DES algorithm written in Liberty Basic and a simple GUI application to play around. It is not a fast implementation which would require a DLL written in C. Maybe, because of this it could be more interesting for some to see MATRIX style, Hollywood movie like HEX numbers floating on the window, a cliche of our times when our hero or heroine sits in front of a display to watch these speeding numbers and bingo gets into deepest secret ICBM launch site, etc.Enjoy.It will get more interesting with public key cryptography on the next article.CryptoManCopyright (c) 2006, Verisoftwww.verisoft.comonur@verisoft.com[[Cryptography with Liberty Basic 102: Classical Cryptography: DES by CryptoMan]]2006