Platforms to show: All Mac Windows Linux Cross-Platform

/Encryption/Crypto


Required plugins for this example: MBS Encryption Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Encryption/Crypto

This example is the version from Thu, 9th Oct 2013.

Project "Crypto.xojo_binary_project"
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class CryptTest Inherits Window
Control InputField Inherits TextField
ControlInstance InputField Inherits TextField
EventHandler Sub GotFocus() PrintHex me.text End EventHandler
EventHandler Function KeyDown(Key As String) As Boolean dim x as string if (asc(Key) = 3) then MiddleField.text = rin.crypt(me.text) return true end if End EventHandler
End Control
Control EKeyField Inherits TextField
ControlInstance EKeyField Inherits TextField
EventHandler Sub GotFocus() PrintHex me.text End EventHandler
End Control
Control EncryptButton Inherits PushButton
ControlInstance EncryptButton Inherits PushButton
EventHandler Sub Action() EncryptedData = rin.crypt(InputField.text) MiddleField.text = EncryptedData End EventHandler
End Control
Control DKeyField Inherits TextField
ControlInstance DKeyField Inherits TextField
EventHandler Sub GotFocus() PrintHex me.text End EventHandler
End Control
Control DecryptButton Inherits PushButton
ControlInstance DecryptButton Inherits PushButton
EventHandler Sub Action() OutputField.text = out.crypt(EncryptedData) End EventHandler
End Control
Control MiddleField Inherits TextField
ControlInstance MiddleField Inherits TextField
EventHandler Sub GotFocus() PrintHex me.text End EventHandler
EventHandler Sub TextChange() OutputField.text = out.crypt(EncryptedData) End EventHandler
End Control
Control OutputField Inherits TextField
ControlInstance OutputField Inherits TextField
EventHandler Sub GotFocus() PrintHex me.text End EventHandler
End Control
Control InitEKey Inherits PushButton
ControlInstance InitEKey Inherits PushButton
EventHandler Sub Action() rin = new RC4MBS( EKeyField.text.ConvertEncoding(encodings.UTF8) ) out = new RC4MBS( EKeyField.text.ConvertEncoding(encodings.UTF8) ) DKeyField.text = EKeyField.text End EventHandler
End Control
Control InitDKey Inherits PushButton
ControlInstance InitDKey Inherits PushButton
EventHandler Sub Action() out = new RC4MBS ( DKeyField.text.ConvertEncoding(encodings.UTF8)) End EventHandler
End Control
Control HexOutput Inherits Label
ControlInstance HexOutput Inherits Label
End Control
EventHandler Sub Open() hashTest.show hmacTest.show benchmarkWindow.show End EventHandler
Sub PrintHex(s as string) HexOutput.text = EncodeHex(s) End Sub
Property EncryptedData As string
Property out As rc4MBS
Property rin As rc4MBS
End Class
Class HashTest Inherits Window
Control InputField Inherits TextField
ControlInstance InputField Inherits TextField
EventHandler Sub TextChange() dim s,t,x as string dim i,j as integer sha1 = new SHA1MBS s = sha1.Hash(InputField.Text) for i = 1 to lenB(s) if (j = 4) then t = t + " " end if j = (j mod 4) + 1 x = hex(ascB(midB(s,i,1))) if (lenB(x) = 1) then x = "0" + x end if t = t + x next OutputField.text = t End EventHandler
End Control
Control OutputField Inherits TextField
ControlInstance OutputField Inherits TextField
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() InputField.text = "abc" ShouldBe.text = "A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D" End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() InputField.text = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" ShouldBe.text = "84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1" End EventHandler
End Control
Control ShouldBe Inherits Label
ControlInstance ShouldBe Inherits Label
End Control
EventHandler Sub Open() me.left = CryptTest.left + 20 End EventHandler
Property Protected sha1 As SHA1MBS
End Class
Class HMACTest Inherits Window
Control KeyField Inherits TextField
ControlInstance KeyField Inherits TextField
EventHandler Sub TextChange() Recalculate End EventHandler
End Control
Control DataField Inherits TextField
ControlInstance DataField Inherits TextField
EventHandler Sub TextChange() Recalculate End EventHandler
End Control
Control OutputField Inherits TextField
ControlInstance OutputField Inherits TextField
End Control
EventHandler Sub Open() me.left = CryptTest.left + 40 Recalculate End EventHandler
Sub Recalculate() dim s,t,x as string dim i,j as integer dim h as SHA1MBS h=new SHA1MBS s = h.HMAC(KeyField.text, DataField.text) for i = 1 to lenB(s) if (j = 4) then t = t + " " end if j = (j mod 4) + 1 x = hex(ascB(midB(s,i,1))) if (lenB(x) = 1) then x = "0" + x end if t = t + x next OutputField.text = t End Sub
End Class
Class BenchmarkWindow Inherits Window
Control BenchmarkButton Inherits PushButton
ControlInstance BenchmarkButton Inherits PushButton
EventHandler Sub Action() dim rc4 as RC4MBS dim sin as string dim i as integer dim x,d as Double rc4 = new RC4MBS("01234567890123456789") for i = 1 to 4096 sin = sin + chrB(floor(rnd*256)) next x = ticks for i = 1 to 100000 sin = rc4.crypt(sin) next x = ticks - x d=x/60 x = 4096.0 * 100000.0 / x x = x * 60.0 / 1024.0 msgBox "Large chunk: " + str(x) + "KB/s in "+str(d)+" seconds." sin = "" for i = 1 to 128 sin = sin + chrB(floor(rnd*256)) next x = ticks for i = 1 to 1000000 sin = rc4.crypt(sin) next x = ticks - x d=x/60 x = 128.0 * 1000000.0 / x x = x * 60.0 / 1024.0 msgBox "Small chunk: " + str(x) + "KB/s "+str(d)+" seconds." End EventHandler
End Control
EventHandler Sub Open() me.left = CryptTest.left + 60 End EventHandler
End Class
Class App Inherits Application
End Class
End Project

The items on this page are in the following plugins: MBS Encryption Plugin.


The biggest plugin in space...