Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77943490
test-medco-crypto-web.go
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 17, 09:19
Size
2 KB
Mime Type
text/x-c
Expires
Mon, Aug 19, 09:19 (2 d)
Engine
blob
Format
Raw Data
Handle
19921855
Attached To
R4897 i2b2-webclient
test-medco-crypto-web.go
View Options
package main
import (
//"github.com/lca1/unlynx/lib"
"github.com/gopherjs/gopherjs/js"
"./mylib"
)
func main() {
js.Global.Set("GenKey", mylib.GenKey)
js.Global.Set("EncryptInt", mylib.EncryptInt)
js.Global.Set("DecryptInt", mylib.DecryptInt)
//js.Global.Set("StrToScal", mylib.StringToScalar)
//js.Global.Set("ScalToStr", mylib.ScalarToString)
//js.Global.Set("StringToScalar", mylib.StringToScalar)
// test that flow works:
//var i int64 = 9000
//secKey, pubKey := mylib.GenKey()
//cipher := mylib.EncryptInt(pubKey, i)
//t0 := time.Now()
//plain := mylib.DecryptInt(cipher, secKey)
//t1 := time.Now()
//
//js.Global.Call("alert", plain)
//js.Global.Call("alert", "Decryption time: " + t1.Sub(t0).String())
// test that the convertions work for the secret key
// TEST 1
//secKey, _ := lib.GenKey()
//secKeyFinal := mylib.StringToScalar(mylib.ScalarToString(secKey))
//is := ""
//if (secKey.Equal(secKeyFinal)) {
// is = "true"
//}else {
// is = "false"
//}
//js.Global.Call("alert", "TO/FROM string: " + is)
//
//secKeyFinal = mylib.ByteToScalar(mylib.ScalarToByte(secKey))
//is = ""
//if (secKey.Equal(secKeyFinal)) {
// is = "true"
//}else {
// is = "false"
//}
//js.Global.Call("alert", "TO/FROM byte: " + is)
// TEST 2
//secKey, _ := lib.GenKey()
//var secKey, _ = lib.GenKey()
//secKeyString := mylib.ScalarToString(secKey)
//js.Global.Get("document").Call("getElementById", "testtext7.2").
// Set("innerHTML", secKeyString)
//secKeyRead := js.Global.Get("document").Call("getElementById", "testtext8.2").
// Get("innerHTML").String()
//is := ""
//if (Check(secKeyRead, secKey)) {
// is = "true"
//}else {
// is = "false"
//}
//js.Global.Call("alert", "are equal: " + is)
// TEST 3
//for i:=0; i < 10; i++{
// sk, pk := lib.GenKey()
// if !(sk.Equal(mylib.StringToScalar(mylib.ScalarToString(sk)))) {
// js.Global.Get("document").Call("getElementById", "testtext7.2").
// Set("innerHTML", "Secret key wrong convertion")
// } else{
// js.Global.Get("document").Call("getElementById", "testtext7.3").
// Set("innerHTML", "Secret key good convertion")
// }
//
// if !(pk.Equal(mylib.StringToPoint(mylib.PointToString(pk)))) {
// js.Global.Get("document").Call("getElementById", "testtext8.2").
// Set("innerHTML", "Public key wrong convertion")
// }else{
// js.Global.Get("document").Call("getElementById", "testtext8.3").
// Set("innerHTML", "Public key good convertion")
// }
//}
}
//func Check(sk string, secKey abstract.Scalar) bool{
// js.Global.Call("alert", "Checking")
// return mylib.StringToScalar(sk).Equal(secKey)
//}
Event Timeline
Log In to Comment