Sonic and Sega Retro Message Board: Blue Sphere Password Algorithm Reverse-Engineered - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
Page 1 of 1
    Locked
    Locked Forum

Blue Sphere Password Algorithm Reverse-Engineered

#1 User is offline ArrowCase 

Posted 05 March 2015 - 08:16 PM

  • Posts: 2
  • Joined: 04-March 15
A while ago I became interested in reverse engineering, recreating, and re-implementing the Blue Sphere minigame in a project all my own (using the art assets directly from the game, otherwise from scratch). My initial search led me to "bsgen," which as you may or may not know is a collection of javascript functions that are able to generate information about each level given the level number or "stage number" (a sort of ID algorithmically associated with each level). These functions, which were originally created by a Japanese coder under the name koryan and later modified slightly by others, have been invaluable to my project. You can find them archived here: http://bsgen-archive.neocities.org/

There are functions to go back and forth between most relevant values: level to stage number, stage to quadrant numbers, level to password, and others. To my knowledge, however, there has been no published example of an algorithm to take a password as input and see if it corresponds to a level number. That is what I have created, made available here in javascript to fit in with the rest of koryan's functions: http://pastebin.com/cnyKdTCr

I commented the code somewhat thoroughly; if anyone wants to know more about it, please ask. I hope anyone who, like I did, stumbles upon Sonic Retro while searching for information about Blue Sphere's algorithms, will be able to learn something from this and put it to good use!

Why was this reversal non-trivial? Well, the javascript in these functions uses arrays of 1s and 0s to carry out what in a non-javascript (read: non-terrible) language should be simple bit operations, and these operations as well as the binary to decimal "password" conversion method used in the script are mildly confusing, and in one important case, non-reversible. Fortunately, I was able to determine that only one "half" of the bit array created in "levtocod" is needed to work backward to the level number — then, that level number can be validated by performing the latter half of levtocod's calculations and seeing if the bit pattern matches the one we got in reverse.

Anyone looking to create versions of this algorithm in other languages should note that the password number is at one point or another treated as one giant integer, and its huge size may exceed the maximum integer value for your language. This is one advantage of javascript: its basic "number" type has a maximum integral size of about 9 trillion.
This post has been edited by Cinossu: 06 March 2015 - 05:28 AM
Reason for edit: Let's make the topic title a bit more descriptive

#2 User is offline nineko 

Posted 06 March 2015 - 12:04 AM

  • I am the Holy Cat
  • Posts: 5341
  • Joined: 17-August 06
  • Gender:Male
  • Location:italy
  • Project:I... don't even know anymore :U
  • Wiki edits:5,251
This is good and all, but I wish you could have written "password algorithm" in the topic title, I was all hyped up when I clicked on this topic, thinking you were talking about the blue sphere contour algorithm instead, since it was brought up again just a few days ago.

#3 User is offline DigitalDuck 

Posted 06 March 2015 - 04:29 AM

  • Arriving four years late.
  • Posts: 3364
  • Joined: 23-June 08
  • Gender:Male
  • Location:Lincs, UK
  • Project:TurBoa, S1RL

View PostArrowCase, on 05 March 2015 - 08:16 PM, said:

Anyone looking to create versions of this algorithm in other languages should note that the password number is at one point or another treated as one giant integer, and its huge size may exceed the maximum integer value for your language. This is one advantage of javascript: its basic "number" type has a maximum integral size of about 9 trillion.


Alternatively just use the word 'long' when you define it in any other language.

#4 User is offline ArrowCase 

Posted 06 March 2015 - 02:00 PM

  • Posts: 2
  • Joined: 04-March 15

View Postnineko, on 06 March 2015 - 12:04 AM, said:

This is good and all, but I wish you could have written "password algorithm" in the topic title, I was all hyped up when I clicked on this topic, thinking you were talking about the blue sphere contour algorithm instead, since it was brought up again just a few days ago.

My bad. Which algorithm is that, may I ask?

#5 User is offline Techokami 

Posted 06 March 2015 - 05:49 PM

  • For use only on NTSC Genesis systems
  • Posts: 1101
  • Joined: 19-November 05
  • Gender:Male
  • Location:HoleNet!
  • Project:Sonic Edge
  • Wiki edits:63

View PostArrowCase, on 06 March 2015 - 02:00 PM, said:

View Postnineko, on 06 March 2015 - 12:04 AM, said:

This is good and all, but I wish you could have written "password algorithm" in the topic title, I was all hyped up when I clicked on this topic, thinking you were talking about the blue sphere contour algorithm instead, since it was brought up again just a few days ago.

My bad. Which algorithm is that, may I ask?

iirc that's the algorithm used to check for when you encase a block of blue spheres with red spheres to make rings. It was brought up recently due to Cinossu making a... "unique" ROM hack that inadvertently highlighted some issues with the algorithm (causing slowdowns and even locking up with certain patterns)

Page 1 of 1
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users