Hittin' dat horseshoe since Nov 2013
it is nice and predictable isn't it?
Working on a long message NXT client for Mac with encryption. Here is the code for dispatching a message, I commented off the encryption so it can easily be run and proven as functional.
Paths to pubkey and privkey will be changed, just a temporary fix.
script AppDelegate
property parent : class "NSObject"
property textField : missing value
property secretPhrase : missing value
property messageFee : missing value
property accountReceiver : missing value
property messageEncrypted : missing value
property keyReceiver : missing value
set rsaPrivate to "/Library/rsaprivkey.pem"
set rsaPublic to "/Library/rsapubkey.pub"
tell application "Finder"
if not exists rsaPrivate as POSIX file then
do shell script "openssl genrsa -out " & rsaPrivate & " 16384"
end if
if not exists rsaPublic as POSIX file then
do shell script "openssl rsa -in " & rsaPrivate & " -pubout > " & rsaPublic
end if
end tell
set rsapubkey to (do shell script "cat " & quoted form of rsaPublic) as text
tell application "Finder"
set theName to name of file 1
end tell
on buttonClicked_(sender)
set feeMessage to (stringValue() of messageFee)
set receiveraccount to (stringValue() of accountReceiver)
set textCipher to "/Library/ciphertext.txt"
-- write receiver's public key to a file--
set rpubPath to "/Library/pubreceiver.key"
set rpubKey to (stringValue() of keyReceiver)
tell application "System Events"
set file_ref to open for access rpubPath with write permission
set eof of file_ref to 0
write ((stringValue() of keyReceiver) as text) to file_ref
close access file_ref
end tell
-- write receiver's public key to a file--
--write plaintext to a file--
set textPlain to "/Library/plaintext.txt"
set message to (stringValue() of textField)
tell application "System Events"
set file_ref2 to open for access textPlain with write permission
set eof of file_ref2 to 0
write ((stringValue() of textField) as text) to file_ref2
close access file_ref2
end tell
--write plaintext to a file--
set ciphertext to do shell script "cat " & quoted form of textPlain
--encrypt plaintext to ciphertext--
-- do shell script "openssl rsautl -encrypt -pubin -inkey " & RpubPath & " -in " & textPlain & " -out " & textCipher
-- set ciphertext to (do shell script "cat " & textCipher)
--encrypt plaintext to ciphertext--
--cipher to hex
set thelist to "0123456789ABCDEF"
set hexvalue to ""
repeat with i in ciphertext
set theAscii to ASCII number of i
set hexvalue to hexvalue & character (theAscii div 16 + 1) of thelist & character (theAscii mod 16 + 1) of thelist
end repeat
set finalText to (hexvalue as text)
--cipher to hex
set messageLength to the length of finalText
set var_a to messageLength / 4
set var_b to var_a / 200
set iterations to round var_b rounding up
set counter to 1
repeat iterations times
if messageLength is less than 800 then
set charnumberalpha to 1
set charnumberbeta to messageLength
else
set charmaximum to messageLength
if counter is equal to iterations then
set charnumberalpha to 1 + 800 * (counter - 1)
set charnumberbeta to charmaximum
else
set charnumberalpha to 1 + 800 * (counter - 1)
set charnumberbeta to 800 + 800 * (counter -1)
end if
end if
set messageFinal to (text charnumberalpha thru charnumberbeta of finalText)
if counter is less than 10 then
set identifierLength to 1
else
set identifierLength to the length of counter
end if
set completeMessage to identifierLength & "000" & counter & "000" & messageFinal
set urlMassive to "http://localhost:7874/nxt?requestType=sendMessage&secretPhrase=" & (stringValue() of secretPhrase) & "&recipient=" & (stringValue() of accountReceiver) & "&fee=" & (stringValue() of messageFee) & "&deadline=1440" & "&message=" & completeMessage
do shell script "open " & quoted form of urlMassive
set counter to counter + 1
end repeat
end buttonClicked_
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
I'm adapting this to upload files onto the blockchain.
zip will be converted to hex
in python this looks like
with open(filename, 'rb') as f:
content = f.read()
print(binascii.hexlify(content))
hex will be truncated and given identifiers
individual messages will be dispatched
master message(s) will be dispatched containing "directory" of information
signature message(s) will be sent to validate master message (s)
to get file
master messages are loaded and checked with signature messages
if true then identifiers will be read and messages will be parsed in ascending order
hex will be converted to zip
posted script contains method of using identifiers.