How to Create Your Own iOS Password Generator | by Victor Catão | Jan, 2022

Harness the power of encryption algorithms

Photo by NeONBRAND on Unsplash

You probably know that it’s not safe to use the same password for everything, right?

Well, I also knew about that, but I ignored the risk until I got a notification in 2019 that was leaked and therefore no longer safe to use. Thus, I thought that I could develop a personal algorithm to generate my passwords according to the service or website.

Like good lazy bones, I thought, “I’m not going to mentally calculate my password every time, right?”. This is how I created an app for my personal use which generates a different password for each service.

Since I liked the result, I decided to share it with all of you.

The algorithm created for this article is different from the one I use in my daily activities, and you can enjoy creating one using your own logic to generate your passwords.

The code generated for this article generates a password based on this structure:

This structure was built thinking about most websites, which were asking you to create a password containing:

  1. Prepare

2. Lowercase letters

3. Capital letters

4. Special Characters

You can add anything you want. You will see how easy it is until the end of this article. Follow me!

First of all, I think it is interesting to explain what “encryption” means. The word comes from the Greek cryptos (“Hidden Secret”) + graphene (“writing”). In short, it seems that converting a readable message to another does not make sense. For example:

In the above case Caesar Cipher It was used to encrypt the message using 3 as Transformation. Was it too mysterious? Relax, I imagined it.

In the next section, I will explain everything. Although before I explain this algorithm, I would like you to know that there are several techniques that you can use to create your own password generator algorithm. Among them:

  • Simple Replacement Blades
  • Replace mono-alphabetic cipher
  • Visionner blades
  • transcoding
  • AutoKey Cipher
  • Vernam blades

Unlike Caesar Salad, Caesar Cipher has this name because it was very much in use by Emperor Julius Caesar. It is one of the most classic script writing techniques and uses the substitution strategy. Each character is replaced with another specified character to create a “mask” of the message.

The traditional technique is used with an alphabetical shift of 3 letters. In this way, each alphabetic letter has its correspondent on the encoded alphabet. So, all you have to do is replace the original letter with its match in the encoded alphabet.

Alphabet Caesar cipher with offset 3.

Now it’s easier to believe HELLO WORLD = KHOOR ZRUOG, the correct? take a look:

Like I said, the traditional technique uses a Transformation From 3 letters, but you can work with any number. In the algorithm that I will cover in this article you will see a dynamic Transformation. Come on guys!

To start the project, simply download it from here. It is important to note that this is not a project with robust architecture, as it is far from the focus of this article. To simplify the project, it was created with MVC + Storyboard.

In this article, you’ll need to look at these two categories:

  • MainViewController: This is just ViewController Application that contains all opinions and actions. In this console, you will find the flag shouldUseBiometricAuthentication Controls whether you want to activate biometric authentication or not (highly recommended if you are going to install the app on your iPhone). Moreover, it also contains the application’s main action logic: encrypt user input using Encrypter Class.
  • Encrypter: This is the most important category in the project, which is Singleton. All the password generation logic is here. Below we have a chapter for that chapter.

The class has only one public method, which is responsible for encoding the user input text.

Looking at the text FacebookThis method will return the generated password 56Jwws(104. ok but how? why? let me show you

You can also watch the entire chapter here.

Before getting started, it is important to remember the coding architecture:

To calculate the first and last random numbers, the algorithm multiplies a random prime number specified in the class by the size of the text sent on the media (Facebook = 8 characters). So:

  • initialNumber = 8 * 7(firstRandomPrimeNumber) = 56
  • finalNumber = 8 * 13(secondRandomPrimeNumber) = 104

there he is! Now the encoded string looks like this:

Next, the algorithm calculates the Caesar cipher with the last 4 digits (maximumCipherSize fixed) from user input: book.

To work dynamically, . is defined Transformation is the entire input volume. Therefore, we calculate the Caesar code for a “book” with an extension Transformation From 8. The string that will be used in the final result will be the return of this function with the first capital letter.

Now the result is almost complete. We already have basically the entire return chain:

Well, all that is missing now is a special character. To calculate it our class has a predefined array with some special characters (specialCharacters).

The algorithm will take a character in a specific position in the list, which is the index constant computed with the remainder dividing the input size by the array size, preventing it from trying to access a position that is not in the array.

Finally, it will return the string:

Easy and useful, right? The idea of ​​this article is to serve as an inspiration for you to build your own password generator algorithm.

You can change the constants of a file Encrypter Describe for something different, and use your imagination when playing with strings, numbers, and special characters.

see you later!

Leave a Comment