Advertisement
TizzyT

XorULong -TizzyT

Jan 12th, 2016
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.27 KB | None | 0 0
  1.     Public Structure XorULong
  2.         Private Shared Rnd As New Random
  3.         Private ReadOnly Secret As ULong
  4.         Private StoredValue, TokenSum, ValueSum As ULong
  5.         Public Sub New(ByRef Token As ULong)
  6.             Secret = BitConverter.ToUInt64(BitConverter.GetBytes(Rnd.NextDouble), 0)
  7.             Token = BitConverter.ToUInt64(BitConverter.GetBytes(Rnd.NextDouble), 0)
  8.             TokenSum = (Secret Xor Token)
  9.         End Sub
  10.         Public Sub Store(ByRef Token As ULong, ByVal Value As ULong)
  11.             If (Secret Xor Token) = TokenSum Then
  12.                 Token = BitConverter.ToUInt64(BitConverter.GetBytes(Rnd.NextDouble), 0)
  13.                 TokenSum = (Secret Xor Token)
  14.                 ValueSum = (Secret Xor Value)
  15.                 StoredValue = (Value Xor Token)
  16.             Else
  17.                 Throw New Exception("Token checksum mismatch")
  18.             End If
  19.         End Sub
  20.         Default Public ReadOnly Property Value(ByVal Token As ULong) As UInteger
  21.             Get
  22.                 Dim R As ULong = (Token Xor StoredValue)
  23.                 If (R Xor Secret) = ValueSum _
  24.                     Then Return R _
  25.                     Else Throw New Exception("Value checksum mismatch")
  26.             End Get
  27.         End Property
  28.     End Structure
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement