Problems computing DHE in GDScript. Works well in Python.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sxkod

Hi all

I am trying to compute shared keys for Diffie - Hellman - Markle to setup a simple encryption for packets from godot to server.

var myP=23017
var myG=2
var mySecret1=35
var mySecret2=59

func _ready():
	var A=fmod(pow(myG,mySecret1),myP)
	var B=fmod(pow(myG,mySecret2),myP)

	var ka=fmod(pow(B,mySecret1),myP)
	var kb=fmod(pow(A,mySecret2),myP)

	print("A ",A)
	print("B ",B)	
	print("KeyA ",ka)
	print("KeyB ",kb)	
	
	
### The above prints an error as below.
#
#A 6802
#B 14994
#KeyA 5067
#KeyB 1370
#

Problem is equivalent code in python correctly calculates the keys but not in godot as you can see above.

I enclose python equivalent below for comparison.
Same code in python parlance is fine as below

myP=23017
myG=2
mySecret1=35
mySecret2=59

A=(myG**mySecret1) % myP
B=(myG**mySecret2) % myP
ka=(B**mySecret1)%myP
kb=(A**mySecret2)%myP

print("A ",A)
print("B ",B)	
print("KeyA ",ka)
print("KeyB ",kb)

# this prints like it should.
('A ', 6802)
('B ', 14994)
('KeyA ', 19738L)
('KeyB ', 19738L)

What am I messing up!
Thanks

No takers?
:frowning:

sxkod | 2019-01-09 17:19