Skip to content

Instantly share code, notes, and snippets.

@gistya
Last active August 24, 2023 19:35
Show Gist options
  • Save gistya/7cab496d7e7a82278e21 to your computer and use it in GitHub Desktop.
Save gistya/7cab496d7e7a82278e21 to your computer and use it in GitHub Desktop.
# Jackie's Universal Cartographics System Code Decoder
# Kay Johnston
# Now with added elegance.
# Updated & Improved by VitaminArrr
import sys
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
divisor = len(alphabet)
middle = divisor**2
biggest = divisor**3
rowlength = 128
sidelength = rowlength**2
def finder(column,row,stack,lettercode):
if lettercode == 'H':
print("AA-A H1-(system code)")
return
elif lettercode == 'G':
cubeside = 640
elif lettercode == 'F':
cubeside = 320
elif lettercode == 'E':
cubeside = 160
elif lettercode == 'D':
cubeside = 80
elif lettercode == 'C':
cubeside = 40
elif lettercode == 'B':
cubeside = 20
elif lettercode == 'A':
cubeside = 10
if row >= cubeside:
row = row - (row % cubeside)
else: row = 0
row = int(row / cubeside)
if stack >= cubeside:
stack = stack - (stack % cubeside)
else: stack = 0
stack = int(stack/cubeside)
if column >= cubeside:
column = column - (column % cubeside)
else: column = 0
column = int(column / cubeside)
position = 0
position += row * sidelength
position += stack * rowlength
position += column
number = int(position / biggest)
working = position - (number * biggest)
number_third = int(working / middle)
third = alphabet[number_third]
working = working - (number_third * middle)
number_second = int(working / divisor)
second = alphabet[number_second]
working = working - (number_second * divisor)
first = alphabet[working]
if number != 0:
text = first + second + '-' + third + ' ' + lettercode + str(number) + '-[SystemNumber]'
else:
text = first + second + '-' + third + ' ' + lettercode + '[SystemNumber]'
print
print 'System name for these coordinates: [Sector Name]',text
print
def reverse(first,second,third,lettercode,first_number,second_number):
position = 0
position += first_number * biggest
for letter in range(divisor):
if alphabet[letter] == third:
position += letter * middle
for letter in range(divisor):
if alphabet[letter] == second:
position += letter * divisor
for letter in range(divisor):
if alphabet[letter] == first:
position += letter
working = position
row = int(working / sidelength)
working = working - (row * sidelength)
stack = int(working / rowlength)
working = working - (stack * rowlength)
column = working
if first_number != 0:
text = first + second + '-' + third + ' ' + lettercode + str(first_number) + '-' + str(second_number)
else:
text = first + second + '-' + third + ' ' + lettercode + str(second_number)
if lettercode == 'H':
cubeside = 1280
elif lettercode == 'G':
cubeside = 640
elif lettercode == 'F':
cubeside = 320
elif lettercode == 'E':
cubeside = 160
elif lettercode == 'D':
cubeside = 80
elif lettercode == 'C':
cubeside = 40
elif lettercode == 'B':
cubeside = 20
elif lettercode == 'A':
cubeside = 10
halfwidth = cubeside / 2
approx_x = (column * cubeside) + halfwidth
approx_y = (row * cubeside) + halfwidth
approx_z = (stack * cubeside) + halfwidth
print
print 'Approximate coordinates of its cube within sector coordinate-space: ','x ~',approx_x,' y ~',approx_y,' z ~',approx_z
print
def man():
print
print("Invalid command. Usage:")
print(" reverse [Letter1] [Letter2] [Letter3] [LetterCode] [Number1] [Number2]")
print(" find [0-1280] [0-1280] [0-1280] [LetterCode]")
print
if len(sys.argv) > 1:
if sys.argv[1] == "reverse":
reverse(sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5],int(sys.argv[6]),int(sys.argv[7]))
elif sys.argv[1] == "find":
finder(int(sys.argv[2]),int(sys.argv[3]),int(sys.argv[4]),sys.argv[5])
else:
man()
else:
man()
@psdevil
Copy link

psdevil commented Sep 17, 2021

Thank you :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment