Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Please note that this is just the parent script in a compiled application. This script utilizes property lists to lookup the associated ASCII code. Running this by itself will result in several errors.
- -- Dropbox link to full application: https://www.dropbox.com/s/7kyt2caa0i3xbo0/Binary%20Translator%20%28x8-3.2%29.zip?dl=0
- -- Initializes variables within closed handlers and sets paths to libraries (0)
- global byte
- global x1
- global x2
- global x3
- global x4
- global x5
- global x6
- global x7
- global x8
- global decimal
- global decimalClass
- global decimalClassFormal
- global code
- global x1a
- global x2a
- global x1b
- global x2b
- global x1c
- global x2c
- global r1
- global r2
- global r3
- global hex
- global x1d
- global x2d
- global x1e
- global x2e
- global x1f
- global x2f
- global r4
- global r5
- global r6
- global octal
- global encoding
- global action
- global title
- set title to "Binary Translator (x8-3.2)"
- set encoding to "Mixed"
- global syscodesPath
- global printcodesPath
- global extracodesPath
- global hexcodesPath
- set syscodesPath to (path to me as string) & "Contents:Resources:library:syscodes.plist"
- set printcodesPath to (path to me as string) & "Contents:Resources:library:printcodes.plist"
- set extracodesPath to (path to me as string) & "Contents:Resources:library:extracodes.plist"
- set hexcodesPath to (path to me as string) & "Contents:Resources:library:hexcodes.plist"
- global restorePath
- set restorePath to (path to me as string) & "Contents:Resources:restore.app"
- on byteInput()
- -- Inputs the byte (1)
- set inputByte to ((round (random number from 0 to 1)) & (round (random number from 0 to 1)) & (round (random number from 0 to 1)) & (round (random number from 0 to 1)) & (round (random number from 0 to 1)) & (round (random number from 0 to 1)) & (round (random number from 0 to 1)) & (round (random number from 0 to 1)))
- set inputByte to (inputByte) as string
- set byte to text returned of (display dialog "Input Byte (x8)" default answer inputByte with icon 1 buttons {"Cancel", "Translate"} default button 2 with title title) as string
- translateBytetoDecimal()
- end byteInput
- byteInput()
- on translateBytetoDecimal()
- -- Checks that the byte is neither greater than or less than eight digits in length (2)
- if ((number of characters of byte) is greater than 8) or ((number of characters of byte) is less than 8) then
- beep
- display alert "An error occured." message "The number of digits cannot be less than or greater than eight. Please try again." & return & return & "Previous Input: " & byte & return & "(Error -001)" as critical buttons {"OK"} default button 1
- byteInput()
- end if
- -- Separates the byte into individual digits (3)
- set x8 to character 1 of byte
- set x7 to character 2 of byte
- set x6 to character 3 of byte
- set x5 to character 4 of byte
- set x4 to character 5 of byte
- set x3 to character 6 of byte
- set x2 to character 7 of byte
- set x1 to character 8 of byte
- -- Translates digit one according to the ASCII table (4)
- if x1 = "1" then
- set x1 to 1
- else if x1 = "0" then
- set x1 to 0
- end if
- -- Translates digit two according to the ASCII table (5)
- if x2 = "1" then
- set x2 to 2
- else if x2 = "0" then
- set x2 to 0
- end if
- -- Translates digit three according to the ASCII table (6)
- if x3 = "1" then
- set x3 to 4
- else if x3 = "0" then
- set x3 to 0
- end if
- -- Translates digit four according to the ASCII table (7)
- if x4 = "1" then
- set x4 to 8
- else if x4 = "0" then
- set x4 to 0
- end if
- -- Translates digit five according to the ASCII table (8)
- if x5 = "1" then
- set x5 to 16
- else if x5 = "0" then
- set x5 to 0
- end if
- -- Translates digit six according to the ASCII table (9)
- if x6 = "1" then
- set x6 to 32
- else if x6 = "0" then
- set x6 to 0
- end if
- -- Translates digit seven according to the ASCII table (10)
- if x7 = "1" then
- set x7 to 64
- else if x7 = "0" then
- set x7 to 0
- end if
- -- Translates digit eight according to the ASCII table (11)
- if x8 = "1" then
- set x8 to 128
- else if x8 = "0" then
- set x8 to 0
- end if
- -- Adds the resulting integers together to create the decimal (12)
- set decimal to (x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8) as number
- -- Determines the class of the decimal (13)
- if (decimal ≥ 0 and decimal < 32) then
- set decimalClass to "syscodes" as string
- set decimalClassFormal to "System Codes"
- else if (decimal > 31 and decimal < 128) then
- set decimalClass to "printcodes" as string
- set decimalClassFormal to "Printable Codes"
- else if (decimal > 127 and decimal < 256) then
- set decimalClass to "extracodes" as string
- set decimalClassFormal to "Special Codes"
- end if
- -- Refers to the appropriate lookup table to locate the associtated code (14)
- set decimal to (decimal) as string
- try
- if decimalClass = "syscodes" then
- tell application "System Events"
- tell property list file syscodesPath
- set code to (value of property list item decimal)
- end tell
- end tell
- else if decimalClass = "printcodes" then
- tell application "System Events"
- tell property list file printcodesPath
- set code to (value of property list item decimal)
- end tell
- end tell
- else if decimalClass = "extracodes" then
- tell application "System Events"
- tell property list file extracodesPath
- set code to (value of property list item decimal)
- end tell
- end tell
- end if
- on error
- locationError()
- end try
- translateDecimaltoHex()
- end translateBytetoDecimal
- translateBytetoDecimal()
- on translateDecimaltoHex()
- -- Third character of hex
- set x1a to (decimal / 16)
- set x2a to (round (decimal / 16) rounding down)
- set r3 to (round (x1a - x2a) * 16)
- -- Second character of hex
- set x1b to (x2a / 16)
- set x2b to (round (x1a / 16) rounding down)
- set r2 to (round (x1b - x2b) * 16)
- -- First character of hex
- set x1c to (x2b / 16)
- set x2c to (round (x1b / 16) rounding down)
- set r1 to (round (x1c - x2c) * 16)
- -- Converts third character to hexadecimal character
- try
- tell application "System Events"
- set r3 to (r3) as string
- tell property list file hexcodesPath
- set r3 to (value of property list item r3)
- end tell
- end tell
- -- Converts second character to hexadecimal character
- tell application "System Events"
- set r2 to (r2) as string
- tell property list file hexcodesPath
- set r2 to (value of property list item r2)
- end tell
- end tell
- -- Converts first character to hexadecimal character
- tell application "System Events"
- set r1 to (r1) as string
- tell property list file hexcodesPath
- set r1 to (value of property list item r1)
- end tell
- end tell
- on error
- locationError()
- end try
- -- Compiles hexadecimal
- set hex to (r1 & r2 & r3)
- set hex to (hex) as string
- translateDecimaltoOctal()
- end translateDecimaltoHex
- translateDecimaltoHex()
- on translateDecimaltoOctal()
- -- Third character of octal
- set x1d to (decimal / 8)
- set x2d to (round (decimal / 8) rounding down)
- set r6 to (round (x1d - x2d) * 8)
- -- Second character of octal
- set x1e to (x2d / 8)
- set x2e to (round (x1d / 8) rounding down)
- set r5 to (round (x1e - x2e) * 8)
- -- First character of octal
- set x1f to (x2e / 8)
- set x2f to (round (x1e / 8) rounding down)
- set r4 to (round (x1f - x2f) * 8)
- -- Compiles octal
- set octal to (r4 & r5 & r6)
- set octal to (octal) as string
- end translateDecimaltoOctal
- translateDecimaltoOctal()
- -- Outputs the translations plus a couple easter eggs (15)
- repeat
- set action to button returned of (display alert byte message "Code: " & code & return & "Encoding: " & encoding & return & "Decimal: " & decimal & return & "Decimal Class: " & decimalClassFormal & return & "Hexadecimal: " & hex & return & "Octal: " & octal buttons {"Credits & Information", "Exit", "Back to Input"} default button 3)
- if action = "Credits & Information" then
- repeat
- set action to button returned of (display alert title message "Developed by Blake Zito" & return & "AppleScript 2.7 (Script Editor)" & return & return & "Description:" & return & "Translates 8-bit binary into its decimal, hexadecimal, octal, and character forms using standard 8-bit ASCII encoding without the use of any primary lookup tables." buttons {"Experimental Features", "Back to Output"} default button 2)
- if action = "Experimental Features" then
- repeat
- set theResult to (display dialog "Enter Password (D-J-S-B)" default answer "" with icon 1 buttons {"Back to Credits & Information", "Unlock"} default button 2 with title "Experimental Features" with hidden answer)
- set answer to (text returned of theResult) as string
- set action to (button returned of theResult) as string
- if action = "Back to Credits & Information" then
- exit repeat
- else if action = "Unlock" then
- tell application "System Events"
- tell property list file hexcodesPath
- set greekMessage to (value of property list item "16")
- if answer = (value of property list item "17") then
- display alert "4 8 15 16 23 42" message greekMessage buttons {"Λορεμ"} default button 1
- open location "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
- else
- beep
- end if
- end tell
- end tell
- end if
- quit
- end repeat
- else if action = "Back to Output" then
- exit repeat
- end if
- end repeat
- else if action = "Exit" then
- quit
- else if action = "Back to Input" then
- byteInput()
- end if
- end repeat
- -- Displays alert in case of location error and attempts to restore libraries (16)
- on locationError()
- beep
- set action to button returned of (display alert "An error occured." message "Some important files couldn't be accessed." & return & "(Error -002)" & return & return & "Restore the libraries to resolve this issue. Restoring will restart the app." as critical buttons {"Restore Libraries"} default button 1)
- open application restorePath
- end locationError
- locationError()
Add Comment
Please, Sign In to add comment