You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.1 KiB
Python
82 lines
2.1 KiB
Python
'''
|
|
Development Notes
|
|
JSON is a common format used to represent structured text.
|
|
|
|
The essence of the program is to introduce noise to disrupt the
|
|
mapping relation of the dictionary.
|
|
|
|
Learning rules is also essential to machine learning.
|
|
|
|
When the rule is disrupted, when I query the dictionary again,
|
|
the message is disrupted.
|
|
|
|
The rule is disrupted by linear arithemetic operation,
|
|
are there more disruptive and complex rules?
|
|
|
|
Prototype to translate a system to text into dictionary
|
|
as a type of structured text
|
|
|
|
str int conversion is important to debug the program
|
|
|
|
why is it that noise is perceived as adverse?
|
|
|
|
'''
|
|
|
|
import numpy as np
|
|
import json
|
|
|
|
# 1 <= key <= 3, silk; 4 <= key <= 6, earth; 7 <= key <= 9, water
|
|
|
|
# perform message decryption process via this mini corpus
|
|
# "no" field is similar to ascii/morse code/unicode coding protocols
|
|
# original message identified by "no" field, no 2 & 3
|
|
# first wrd
|
|
|
|
# disrupted message idenfified by "no" field
|
|
|
|
data = json.load(open('seed.json', 'r'))
|
|
|
|
print("before disrupting, the message is: ")
|
|
|
|
for i in data:
|
|
print(i)
|
|
if i["no"] == "2":
|
|
print(i["glyph"] + " " + i["radical"] )
|
|
if i["no"] == "3":
|
|
print(i["glyph"] + " " + i["radical"] )
|
|
|
|
# write as a function, input are codes, output are a {} of glyphs
|
|
|
|
noise = np.random.randint(1,3)
|
|
|
|
for i in data:
|
|
i["no"] = int(i["no"])
|
|
i["no"] += noise
|
|
|
|
with open('noised.json','w') as w_file:
|
|
json.dump(data,w_file, indent=4)
|
|
|
|
print("after disrupting, the message is: ")
|
|
|
|
# use noised json to decrypt
|
|
|
|
noise_data = json.load(open('noised.json','r'))
|
|
for i in noise_data:
|
|
print(i)
|
|
print(type(i["no"]))
|
|
# comparing integers, the noise_data no fields are previously
|
|
# dumped as integers
|
|
if i["no"] == 2:
|
|
print(i["glyph"] + " " + i["radical"] )
|
|
if i["no"] == 3:
|
|
print(i["glyph"] + " " + i["radical"] )
|
|
|
|
# at this point the interferences are not so apparent
|
|
|
|
# test with a large corpus
|
|
|
|
# try with corpuses of different language
|
|
|
|
# try a chinese dictionary and a latin dictionary
|
|
|
|
# and any other types of dictionary structures, remix! |