-
Notifications
You must be signed in to change notification settings - Fork 0
/
Offset.gd
79 lines (66 loc) · 2.14 KB
/
Offset.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
extends VBoxContainer
onready var error_message = self.get_parent().get_child(1)
func _ready():
pass # Replace with function body.
func convert_text_to_vals(x : String):
var array : PoolIntArray = []
for i in x:
array.append(ord(i)-0x61)
return array
func convert_vals_to_text(x: PoolIntArray):
var text = ""
for i in x:
text += char(i+0x61)
return text
func convert_vals_to_indices(x : PoolIntArray):
var text = ""
for i in x:
text += str(i)+" "
return text.substr(0, text.length()-1)
func convert_indices_to_vals(x: String):
var split = x.split(" ")
var array : PoolIntArray = []
for i in split:
array.append(int(i))
return array
func calculate_text():
error_message.text = ""
var ciphervals : PoolIntArray = $Ciphertext.indices
var offsets : PoolIntArray = $Offsets.indices
var text_indices = []
for i in ciphervals.size():
text_indices.append((ciphervals[i]-offsets[i%offsets.size()]+26)%26)
$Text.indices = text_indices
$Text/TextEdit.text = convert_vals_to_text(text_indices)
$Text/TextEdit2.text = convert_vals_to_indices(text_indices)
clear_edits()
func calculate_offsets():
var text_indices : PoolIntArray = $Text.indices
var ciphervals : PoolIntArray = $Ciphertext.indices
if text_indices.size() != ciphervals.size():
error_message.text = "Text and cipher are not the same size!"
return
else:
error_message.text = ""
var offsets = []
for i in text_indices.size():
offsets.append((ciphervals[i]-text_indices[i]+26) % 26)
$Offsets.indices = offsets
$Offsets/TextEdit.text = convert_vals_to_text(offsets)
$Offsets/TextEdit2.text = convert_vals_to_indices(offsets)
clear_edits()
func calculate_ciphertext():
error_message.text = ""
var text_indices : PoolIntArray = $Text.indices
var offsets : PoolIntArray = $Offsets.indices
var ciphervals = []
for i in text_indices.size():
ciphervals.append((text_indices[i]+offsets[i % offsets.size()]) % 26)
$Ciphertext.indices = ciphervals
$Ciphertext/TextEdit.text = convert_vals_to_text(ciphervals)
$Ciphertext/TextEdit2.text = convert_vals_to_indices(ciphervals)
clear_edits()
func clear_edits():
$Text.clear_edits()
$Ciphertext.clear_edits()
$Offsets.clear_edits()