Advertisement
ASBusinessMagnet

A real-life Fan Fiction Application

Aug 18th, 2011
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; contents of the source code:
  2.  
  3. Procedure.s Decoding(to_decode.s, key.s)
  4.  
  5.   result.s = ""
  6.  
  7.   ; alphanumeric system needed: a-z = 0-25, A-Z = 26-51, 0-9 = 52-61 (mod 62)
  8.  
  9.   length_t = Len(to_decode)
  10.   length_k = Len(key)
  11.  
  12.   Dim text_letters(length_t)
  13.   Dim key_letters(length_k)
  14.  
  15.   For i = 1 To length_t
  16.     my_number = Asc(Right(to_decode, length_t-i+1))
  17.     Select my_number
  18.       Case 48 To 57 ; number
  19.         text_letters(i) = my_number + 4
  20.       Case 65 To 90 ; uppercase letter
  21.         text_letters(i) = my_number - 39
  22.       Case 97 To 122 ; lowercase letter
  23.         text_letters(i) = my_number - 97
  24.       Default ; undefined
  25.         Debug "Error: string to decode contains non-alphanumeric characters"
  26.         End
  27.     EndSelect
  28.   Next
  29.  
  30.   For i = 1 To length_k
  31.     my_number = Asc(Right(key, length_k-i+1))
  32.     Select my_number
  33.       Case 48 To 57 ; number
  34.         key_letters(i) = my_number + 4
  35.       Case 65 To 90 ; uppercase letter
  36.         key_letters(i) = my_number - 39
  37.       Case 97 To 122 ; lowercase letter
  38.         key_letters(i) = my_number - 97
  39.       Default ; undefined
  40.         Debug "Error: key contains non-alphanumeric characters"
  41.         End
  42.     EndSelect    
  43.   Next
  44.  
  45.   For i = 1 To length_t
  46.     key_letter_used = (i-1) % length_k + 1
  47.     my_number = (text_letters(i) - key_letters(key_letter_used) + 62) % 62
  48.     Select my_number
  49.       Case 0 To 25 ; lowercase letter
  50.         result + Chr(my_number + 97)    
  51.       Case 26 To 51 ; uppercase letter
  52.         result + Chr(my_number + 39)  
  53.       Case 52 To 61 ; number
  54.         result + Chr(my_number - 4)
  55.       Default ; undefined
  56.         Debug "Error: incorrect modulo arithmetics"
  57.         End
  58.     EndSelect
  59.   Next
  60.  
  61.   ProcedureReturn result
  62.  
  63. EndProcedure
  64.  
  65. ; introduction
  66.  
  67. OpenConsole()
  68. EnableGraphicalConsole(1)
  69. PrintN("Aperture Science BBS System Fan Fiction Application, version 19.1.0.4")
  70.  
  71. ; the last number is the number of days I worked on this thing + the number of side programs I've written;
  72. ; how much you're going to bet on the number not reaching two digits?
  73.  
  74. PrintN("Handling humanity's history since Jesus Christ")
  75. PrintN("")
  76.  
  77. ; login
  78.  
  79. Dim logins.s(2, 1)
  80. i = 1
  81. OpenFile(0, "./global_dir/logins.txt")
  82. key.s = ReadString(0)
  83. While Not Eof(0)
  84.   username.s = ReadString(0)
  85.   password_encoded.s = ReadString(0)
  86.   password.s = Decoding(password_encoded, key)
  87.   logins(1, i) = username
  88.   logins(2, i) = password
  89.   i + 1
  90.   ReDim logins(2, i)
  91. Wend
  92. i - 1
  93. CloseFile(0)
  94.  
  95. ; good luck figuring out what ASBusinessMagnet's, interdimensionalPortaller's
  96. ; and WheatleyMoronic's passwords are
  97.  
  98. PrintN("Please log in to the system in order to use it.")
  99. lines = 4
  100. Username:
  101. Print("Username: ")
  102. lines + 1
  103. username.s = Input()
  104. If username = "quit"
  105.   End
  106. EndIf
  107. okay = 0
  108. For j = 1 To i
  109.   If logins(1, j) = username
  110.     okay = 1
  111.     check = j
  112.   EndIf
  113. Next
  114. If okay = 0
  115.   PrintN("No such username found within the database, access denied.")
  116.   PrintN("")
  117.   PrintN("Please try again or type "+Chr('"')+"quit"+Chr('"')+" to exit the Application.")
  118.   lines  + 3
  119.   Goto Username
  120. EndIf
  121. key2 = -1
  122. Print("Password: ")
  123. lines + 1
  124. password = ""
  125. chars = 0
  126. Repeat
  127.   key.s = Inkey()
  128.   If key <> ""
  129.     key2 = RawKey()
  130.     If key2 = 8 And chars <> 0
  131.       If chars = 1 : password = "" : Else : password = Left(password, Len(password)-1) : EndIf
  132.       chars - 1
  133.       ConsoleLocate(chars+10, lines-1)
  134.       Print(" ")
  135.       ConsoleLocate(chars+10, lines-1)
  136.     ElseIf key2 = 13
  137.     ElseIf key2 = 8 And chars = 0
  138.     Else
  139.       password = password + key
  140.       chars + 1
  141.       Print("*")
  142.     EndIf
  143.   EndIf
  144. Until key2 = 13
  145. PrintN("")
  146. If password = logins(2, check)
  147.   PrintN("Access granted.")
  148.   lines + 1
  149.   Goto MainLoop
  150. Else
  151.   PrintN("Password incorrect, access denied.")
  152.   PrintN("")
  153.   PrintN("Please try again Or type "+Chr(34)+"quit"+Chr(34)+" To exit the Application.")
  154.   lines + 3
  155.   Goto Username
  156. EndIf
  157.  
  158. MainLoop:
  159.  
  160. Repeat
  161.   PrintN("")
  162.   Print("> ")
  163.   command.s = Input()
  164.   PrintN("")
  165.   lines + 3
  166.   command + " "
  167.   first_pos = FindString(command, " ", 1)
  168.   first_word.s = Left(command, first_pos-1)
  169.   Select first_word
  170.     Case "logout"
  171.       PrintN("Successfully logged out.")
  172.       PrintN("")
  173.       lines + 2
  174.       Goto Username
  175.     Case "dir"
  176.       Gosub dir
  177.     Case "years"
  178.       Gosub years
  179.     Case "quit"
  180.       PrintN("Quitting...")
  181.     Default
  182.       PrintN("No such command.")
  183.       lines + 1
  184.   EndSelect
  185. Until first_word = "quit"
  186.  
  187. CloseConsole()
  188.  
  189. End
  190.  
  191. dir:
  192.  
  193. PrintN("Directory listing:")
  194. PrintN("")
  195. lines + 2
  196. files = 0
  197. folders = 0
  198. Directory$ = ".\local_dir\"
  199. ; separate examinations for first folders then files
  200. If ExamineDirectory(0, Directory$, "*.*")  
  201.   While NextDirectoryEntry(0)
  202.     If DirectoryEntryType(0) <> #PB_DirectoryEntry_File
  203.       foldername.s = DirectoryEntryName(0)
  204.       Select foldername
  205.         Case "."
  206.         Case ".."
  207.           PrintN(DirectoryEntryName(0))
  208.           lines + 1
  209.         Default
  210.           folders + 1
  211.           PrintN(DirectoryEntryName(0))
  212.           lines + 1
  213.       EndSelect
  214.     EndIf  
  215.   Wend
  216. EndIf
  217. FinishDirectory(0)
  218. If ExamineDirectory(1, Directory$, "*.*")  
  219.   While NextDirectoryEntry(1)
  220.     If DirectoryEntryType(1) = #PB_DirectoryEntry_File
  221.       files + 1
  222.       PrintN(DirectoryEntryName(1))
  223.       lines + 1
  224.     EndIf  
  225.   Wend
  226. EndIf
  227. FinishDirectory(1)
  228. PrintN("")
  229. Print(Str(folders)+" folder")
  230. If folders % 10 <> 1 Or (folders % 100) / 10 = 1
  231.   Print("s")
  232. EndIf
  233. Print(", "+Str(files)+" file")
  234. If files % 10 <> 1 Or (files % 100) / 10 = 1
  235.   Print("s")
  236. EndIf
  237. PrintN(" in total.")
  238. lines + 2
  239.  
  240. Return
  241.  
  242. years:
  243.  
  244. PrintN("Year listing:")
  245. PrintN("")
  246. lines + 2
  247. OpenFile(1, "./global_dir/years.txt")
  248. ReadString(1) ; reading useless note
  249. timeline_count = 0
  250. Dim timeline_catalogue.s(4, 1)
  251. timeline_codename.s = ReadString(1)
  252. While timeline_codename <> "[YEAR]"
  253.   timeline_name.s = ReadString(1)
  254.   bc_prefix.s = ReadString(1)
  255.   ad_prefix.s = ReadString(1)
  256.   timeline_count + 1
  257.   ReDim timeline_catalogue(4, timeline_count)
  258.   timeline_catalogue(1, timeline_count) = timeline_codename
  259.   timeline_catalogue(2, timeline_count) = timeline_name
  260.   timeline_catalogue(3, timeline_count) = bc_prefix
  261.   timeline_catalogue(4, timeline_count) = ad_prefix
  262.   timeline_codename.s = ReadString(1)
  263. Wend
  264. year_count = 0
  265. Dim year_catalogue.s(2, 1)
  266. While Not Eof(1)
  267.   year_name.s = ReadString(1)
  268.   year_timeline.s = ReadString(1)
  269.   year_foldername.s = ReadString(1)
  270. Wend
  271.  
  272. ; still to be done...
  273.  
  274. Return
  275.  
  276. ; contents of file global_dir/logins.txt:
  277.  
  278. ; ASBBSSFFA
  279. ; ASBusinessMagnet
  280. ; f6SUS3oMEubId03QJNN0VN
  281. ; interdimensionalPortaller
  282. ; jZF236TIYhSJOT61X5RSODZ0XJ
  283. ; WheatleyMoronic
  284. ; 8iNe6b5hOR6O
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement