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

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

  
'HOW TO USE THESE FUNCTIONS:
'EXAMPLE:
'C$=ENCRYPT(A$,B$) OR C$=DECRYPT(A$,B$)
'WHERE
    'A$=TEXT TO BE ENCYPTED/DECRYPTED
    'B$=PASSWORD FOR ENCRYPTION  (SHOULD BE THE SAME FOR ENCRYPT AND DECRYPT)
    'C$=RESULT

     DECLARE FUNCTION encrypt(text AS STRING, pass AS STRING)AS STRING
     DECLARE FUNCTION decrypt(text AS STRING, pass AS STRING)AS STRING

     FUNCTION encrypt
      DIM a AS INTEGER:DIM lettert AS STRING:DIM letterp AS STRING
      DIM asct AS INTEGER:DIM ascp AS INTEGER:DIM count AS INTEGER
      count = 1 'set the counter to 1
      FOR a = 1 TO LEN(text) 'start the algorithm
       lettert = MID$(text, a,1) 'get one letter of the text
       letterp = MID$(pass, count,1) 'get one letter of the password
       asct = ASC(lettert) 'get the ascii value for the letter in the text
       ascp = ASC(letterp) 'get th    e ascii value for the letter in the password
       asct = asct + ascp 'add the ascii values together
       IF asct > 255 THEN asct = asct - 255 'make sure the ascii code does not exceed the limit
       lettert = CHR$(asct) 'convert the ascii code to a character
       Result = Result & lettert 'add the new letter to the final result
       count = count + 1 'increment the counter
       IF count > LEN(pass) THEN count = 1 'check to see if the counter is higher than the number of letters in the password, if so count = 1
      NEXT a
     END FUNCTION

     FUNCTION decrypt
      DIM a AS INTEGER:DIM lettert AS STRING:DIM letterp AS STRING
      DIM asct AS INTEGER:DIM ascp AS INTEGER:DIM final AS STRING
      DIM count AS INTEGER
      count = 1 'set the counter to 1
      FOR a = 1 TO LEN(text) 'start the algorithm
       lettert = MID$(text, a,1) 'get one letter of the text
       letterp = MID$(pass, count,1) 'get one letter of the password
       asct = ASC(lettert) 'get the ascii value for the letter in the text
       ascp = ASC(letterp) 'get the ascii value for the letter in the password
       asct = asct - ascp 'subtract the ascii values
       IF asct > 255 THEN asct = asct - 255 'make sure the ascii code does not fall below 0
       lettert = CHR$(asct) 'convert the ascii code to a character
       Result = Result & lettert 'add the new letter to the final result
       count = count + 1 'increment the counter
       IF count > LEN(pass) THEN count = 1 'check to see if the counter is higher than the number of letters in the password, if so count = 1
      NEXT a
     END FUNCTION
掌柜推荐
 
 
¥1,800.00 ·
 
 
¥489.00 ·
 
 
¥288.00 ·
 
 
¥908.00 ·
 
 
¥748.00 ·
 
 
¥264.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-19 07:57:22