Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Structure XorULong
- Private Shared Rnd As New Random
- Private ReadOnly Secret As ULong
- Private StoredValue, TokenSum, ValueSum As ULong
- Public Sub New(ByRef Token As ULong)
- Secret = BitConverter.ToUInt64(BitConverter.GetBytes(Rnd.NextDouble), 0)
- Token = BitConverter.ToUInt64(BitConverter.GetBytes(Rnd.NextDouble), 0)
- TokenSum = (Secret Xor Token)
- End Sub
- Public Sub Store(ByRef Token As ULong, ByVal Value As ULong)
- If (Secret Xor Token) = TokenSum Then
- Token = BitConverter.ToUInt64(BitConverter.GetBytes(Rnd.NextDouble), 0)
- TokenSum = (Secret Xor Token)
- ValueSum = (Secret Xor Value)
- StoredValue = (Value Xor Token)
- Else
- Throw New Exception("Token checksum mismatch")
- End If
- End Sub
- Default Public ReadOnly Property Value(ByVal Token As ULong) As UInteger
- Get
- Dim R As ULong = (Token Xor StoredValue)
- If (R Xor Secret) = ValueSum _
- Then Return R _
- Else Throw New Exception("Value checksum mismatch")
- End Get
- End Property
- End Structure
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement