Author

Topic: NXT messaging client code... (Read 656 times)

legendary
Activity: 1232
Merit: 1001
January 17, 2014, 04:30:39 AM
#2
Wrong Forum.

Ask your questions here: https://nextcoin.org/
newbie
Activity: 56
Merit: 0
January 17, 2014, 04:14:10 AM
#1
 Lost my laptop in Mexico and I didn't have my password here backed up. I threw together this code today during lunch, it is in applescript, with resources in objectivec.

It functions as a NXT messenger for Mac.

Should I change this to an ECC algorithm?

I am adapting this code without the encryption to act as a raw data uploader, a file will be converted to binary, then hex and truncated at 900 character intervals to be uploaded to the blockchain in segments.


Code:
script AppDelegate
   
property parent : class "NSObject"
    property textField : missing value
   
    property secretPhrase : missing value
    property messageFee : missing value
    property accountReceiver : 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
   set (stringValue() of text field "field" ) of window "main" to rsapubkey
   
    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--
       
        --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 / 6
         
         set var_b to var_a / 150
         
         set iterations to round var_b rounding up
         
         set counter to 1
         repeat iterations times
             
             if messageLength is less than 900 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 + 900 * (counter - 1)
                    set charnumberbeta to charmaximum
                 
                    else
                 
                    set charnumberalpha to 1 + 900 * (counter - 1)
                    set charnumberbeta to 900 + 900 * (counter -1)
                 
                 end if
             
             end if
             
             set messageFinal to (text charnumberalpha thru charnumberbeta of finalText)
             
             set urlMassive to  "http://localhost:7874/nxt?requestType=sendMessage&secretPhrase=" & (stringValue() of secretPhrase) & "&recipient=" &  (stringValue() of accountReceiver) & "&fee=" & (stringValue() of messageFee) & "&deadline=1440" & "&message=" & messageFinal
             
             tell application "Safari"
                 launch
                 set the URL of document iterations to urlMassive
             end tell
             
             
             set counter to counter + 1
         end repeat
Jump to: