Results 1 to 12 of 12

Thread: Encrypt/Decrypt

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Question Encrypt/Decrypt

    Hey All,

    Can someone show me a simple encrypt/decrypt code that only
    uses the following characters...

    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    abcdefghijklmnopqrstuvwxyz
    0123456789

    I just do not understand how to do it.

    Thanks in advance,
    Ron

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154
    I'm sorry ...I forgot something.

    It needs to use a changeable password.

    Thanks

  3. #3
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677
    That would be Base64. Here is how to encode and decode Base64:

    VB Code:
    1. Public Function DecodeBase64String(ByVal str2Decode As String) As String
    2.  
    3. ' ******************************************************************************
    4. '
    5. ' Synopsis:     Decode a Base 64 string
    6. '
    7. ' Parameters:   str2Decode  - The base 64 encoded input string
    8. '
    9. ' Return:       decoded string
    10. '
    11. ' Description:
    12. ' Coerce 4 base 64 encoded bytes into 3 decoded bytes by converting 4, 6 bit
    13. ' values (0 to 63) into 3, 8 bit values. Transform the 8 bit value into its
    14. ' ascii character equivalent. Stop converting at the end of the input string
    15. ' or when the first '=' (equal sign) is encountered.
    16. '
    17. ' ******************************************************************************
    18.  
    19.     Dim lPtr            As Long
    20.     Dim iValue          As Integer
    21.     Dim iLen            As Integer
    22.     Dim iCtr            As Integer
    23.     Dim Bits(1 To 4)    As Byte
    24.     Dim strDecode       As String
    25.  
    26.     ' for each 4 character group....
    27.     For lPtr = 1 To Len(str2Decode) Step 4
    28.         iLen = 4
    29.         For iCtr = 0 To 3
    30.             ' retrive the base 64 value, 4 at a time
    31.             iValue = InStr(1, BASE64CHR, Mid$(str2Decode, lPtr + iCtr, 1), vbBinaryCompare)
    32.             Select Case iValue
    33.                 ' A~Za~z0~9+/
    34.                 Case 1 To 64: Bits(iCtr + 1) = iValue - 1
    35.                 ' =
    36.                 Case 65
    37.                     iLen = iCtr
    38.                     Exit For
    39.                 ' not found
    40.                 Case 0: Exit Function
    41.             End Select
    42.         Next
    43.  
    44.         ' convert the 4, 6 bit values into 3, 8 bit values
    45.         Bits(1) = Bits(1) * &H4 + (Bits(2) And &H30) \ &H10
    46.         Bits(2) = (Bits(2) And &HF) * &H10 + (Bits(3) And &H3C) \ &H4
    47.         Bits(3) = (Bits(3) And &H3) * &H40 + Bits(4)
    48.  
    49.         ' add the three new characters to the output string
    50.         For iCtr = 1 To iLen - 1
    51.             strDecode = strDecode & Chr$(Bits(iCtr))
    52.         Next
    53.  
    54.     Next
    55.  
    56.     DecodeBase64String = strDecode
    57.  
    58. End Function
    59. Function Encode64(InputStr As String) As String
    60.     Dim State As Integer
    61.     Dim i As Integer
    62.     Dim Base64
    63.     Dim current As Integer
    64.     Dim old As Integer
    65.     Dim first_new As String
    66.     Dim second_new As String
    67.     Dim Output As String
    68.    
    69.     Base64 = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", _
    70.                    "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", _
    71.                    "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", _
    72.                    "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", _
    73.                    "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/")
    74.    
    75.     For i = 1 To Len(InputStr)
    76.          State = State + 1
    77.          Select Case State
    78.          Case 1
    79.              current = Asc(Mid(InputStr, i, 1))
    80.              first_new = Base64((Int(current / 4) And &H3F))
    81.              Output = Output & first_new
    82.          Case 2
    83.              current = Asc(Mid(InputStr, i, 1))
    84.              first_new = Base64((((old * 16) And &H30) Or ((Int(current / 16) And &HF))))
    85.              Output = Output & first_new
    86.          Case 3:
    87.              current = Asc(Mid(InputStr, i, 1))
    88.              first_new = Base64((((old * 4) And &H3C) Or ((Int(current / 64) And &H3))))
    89.              second_new = Base64((current And &H3F))
    90.              Output = Output & first_new & second_new
    91.              State = 0
    92.          End Select
    93.          old = current
    94.      Next
    95.      Select Case State
    96.      Case 1
    97.          first_new = Base64(((old * 16) And &H30))
    98.          Output = Output & first_new & "=="
    99.      Case 2
    100.          first_new = Base64(((old * 4) And &H3C))
    101.          Output = Output & first_new & "="
    102.      End Select
    103.      Encode64 = Output
    104. End Function

    HTH, Jeremy
    He who listens well, speaks well.

  4. #4
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677
    You also need these at the top of the code:

    VB Code:
    1. Option Compare Text
    2. Private pbBase64Byt(0 To 63)    As Byte             ' base 64 encoder byte array
    3. Private Const BASE64CHR As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
    He who listens well, speaks well.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154
    Oh well hell...my mind is fried today or something. How would
    you use it?

    Thanks JC

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154
    I think mavbe I figuered it out.

    Is there anyway to put a password key into that?

  7. #7
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677
    Here is a sample program:


    Let me know if it's what you seek, Jeremy
    Attached Files Attached Files
    He who listens well, speaks well.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154
    Hey Thanks JC.

    What I meant was is there any way to put a key into the
    encryption? You know, an encryption with a password.

  9. #9
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    base64 isn't an encryption... it is for sending binary files over the internet when the protocol can only use the limited ascii characters (ie newsgroups).
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  10. #10
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677
    I agree it's not "encryption" but it does alter a string and put it into another form, making it harder to see what the actual password and user id is. Although it's not technically encryption, it is used during SMTP AUTH to encode and decode the username and password. Cody, I don't understand what you are asking. It's been a long day. Explain it to me and I'll help. HTH, Jeremy
    He who listens well, speaks well.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Smile

    Hey JC ... that's OK, what you showed me will work just fine.

    Thanks alot for your help, I really appreciate it.

    Ron

  12. #12
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677
    Are you sure? I can help you out I just think that I misunderstood your question. Let me know, Jeremy
    He who listens well, speaks well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width