ASP function to encrypt ID (number only)


/ Published in: ASP
Save to your folder(s)

These are two function used to encrypt and decrypt the ID you don't want to show (for example the id of the user to be saved in the cookies...)


Copy this code and paste it in your HTML
  1. Function Encrypt(theNumber)
  2. Dim n, szEnc, t, HiN, LoN, i
  3. n = CDbl((theNumber + 1570) ^ 2 - 7 * (theNumber + 1570) - 450)
  4. If n < 0 Then szEnc = "R" Else szEnc = "J"
  5. n = CStr(abs(n))
  6. For i = 1 To Len(n) step 2
  7. t = Mid(n, i, 2)
  8. If Len(t) = 1 Then
  9. szEnc = szEnc & t
  10. Exit For
  11. End If
  12. HiN = (CInt(t) And 240) / 16
  13. LoN = CInt(t) And 15
  14. szEnc = szEnc & Chr(Asc("M") + HiN) & Chr(Asc("C") + LoN)
  15. Next
  16. Encrypt = szEnc
  17. End Function
  18.  
  19. Function Decrypt(theNumber)
  20. On Error Resume Next
  21. Dim e, n, sign, t, HiN, LoN, NewN, i
  22. e = theNumber
  23. If Left(e, 1) = "R" Then sign = -1 Else sign = 1
  24. e = Mid(e, 2)
  25. NewN = ""
  26. For i = 1 To Len(e) step 2
  27. t = Mid(e, i, 2)
  28. If Asc(t) >= Asc("0") And Asc(t) <= Asc("9") Then
  29. NewN = NewN & t
  30. Exit For
  31. End If
  32. HiN = Mid(t, 1, 1)
  33. LoN = Mid(t, 2, 1)
  34. HiN = (Asc(HiN) - Asc("M")) * 16
  35. LoN = Asc(LoN) - Asc("C")
  36. t = CStr(HiN Or LoN)
  37. If Len(t) = 1 Then t = "0" & t
  38. NewN = NewN & t
  39. Next
  40. e = CDbl(NewN) * sign
  41. Decrypt = CLng((7 + sqr(49 - 4 * (-450 - e))) / 2 - 1570)
  42. End Function

URL: http://www.barattalo.it/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.