Guidance
指路人
g.yi.org
software / rapidq / Examples / String & Text / Encryption / encrypt1 / crypt101.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'
' a text file encryption and decryption routine created with Rapid-Q
' 5/28/00
' Scott aka Sand Dune
'
     $INCLUDE "rapidq.inc"

     DECLARE SUB do_it           ' the subroutine "do_it" encrypts and decrypts the text

     DIM lin$        AS STRING   ' this holds each line of text that we will process
     DIM kar$        AS STRING   ' this holds each character in a line
     DIM pass$       AS STRING   ' the password is used to scramble each character in the text
     DIM new_kar$    AS STRING   ' the new character created when scrambling or unscrambling
     DIM new_line$   AS STRING   ' the new line created when scrambling or unscrambling
     DIM mode$       AS STRING   ' a flag to determine whether to encrypt (1) or decrypt (0)
     DIM line_len#   AS INTEGER  ' the length of the line to loop through when processing
     DIM line_loop#  AS INTEGER  ' the line counter when looping thru each character in the line
     DIM kar#        AS INTEGER  ' the ascii equivalent of the character being processed
     DIM scram#      AS INTEGER  ' the modulo remainder used when scrambling eggs (or undoing)
     DIM pass_len#   AS INTEGER  ' the length of the password used in the cryptography formula
'----------------------------------------------------------------------------------------
' assign some text and show it, call the encrypt routine, show it, decrypt it, show it
'
     pass$ = "wrialpliidaqm"   ' password containing "william" and "rapidq" every other letter
     pass_len# = LEN(pass$)    ' the length of the password that was so cleverly designed

     lin$ = "Scott is called Sand Dune because he lives near the Atlantic Ocean" ' text2encrypt
     ?lin$                     ' show the text before doing anything to it

     mode$ = "1"               ' set the flag for encrypting the data (scramble them eggs)
     do_it                     ' call the subroutine to "do it"
     ?new_line$                ' show the encryption results

     lin$ = new_line$          ' assign the encrypted line to be decrypted
     mode$ = "0"               ' set the flag for decrypting the data (unscramble)
     do_it                     ' call the subroutine to "do it"
     ?new_line$                ' show the decryption results

' the end                   ' normal end of program
'----------------------------------------------------------------------------------------
' the little engine that does the work
'
     SUB do_it                   ' this subroutine encrypts and decrypts text based on "mode$"
'
      line_len# = LEN(lin$)                             ' get the length of the line to do
      new_line$ = ""                                    ' initialize a new line to create
      FOR line_loop# = 1 TO line_len#                   ' loop thru each character in line
       kar$ = MID$(lin$, line_loop#, 1)                ' extract individual character
       kar# = ASC(kar$)                                ' get ascii value of that character
       scram# = line_loop# MOD pass_len#               ' get remainder of pos and pass len
       IF mode$ = "1" THEN                             ' if parameter one is a "1"
        kar# = kar# + ASC( MID$(pass$, scram#, 1) )   '   encrypt the character
       ELSE                                            ' or else it is a "0" and we should
        kar# = kar# - ASC( MID$(pass$, scram#, 1) )   '   decrypt the character
       END IF                                          ' end of 'if parameter is "1"
       new_kar$ = CHR$(kar#)                           ' assign the new character
       new_line$ = new_line$ + new_kar$                ' append it to the new output line
      NEXT                                              ' end of loop thru each character
'
     END SUB
'----------------------------------------------------------------------------------------
掌柜推荐
 
 
¥1,390.00 ·
 
 
¥287.00 ·
 
 
¥410.00 ·
 
 
¥1,380.00 ·
 
 
¥1,080.00 ·
 
 
¥271.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-19 07:57:22