Buscar este blog

jueves, 18 de febrero de 2016

C++ example with input arguments using flags


I know it's been a long while since I last posted something in the blog. I just came across it some days ago and decided that I wanted to start writing again on it. So I will try to keep updating the blog from now on :)

Today's post is about a very simple, yet extremely common tool in programming: input arguments to programs. Whenever one launches a program from the terminal in Ubuntu (or command prompt in Windows), it is very normal to pass on arguments that are usually predefined by flags. In bash shell scripting language, one cannot actually think of programs that don't require input arguments. The example above is a really simple example of how this flags can be implemented to collect input arguments from the terminal (whenever the appropriate executable file has been created -using the g++ compiler, for example). This is a very simple implementation of a telephone list, where a new user is added via the flags as input arguments to the program, and the inputted user is then saved on to a file using the appropriate C++ classes (if- and ofstream).

So, as it used to be before, here are some examples of what the user may input:
  • Example 1: no input arguments. Since a user can only be added to the file through the command line, the program exits.

  •  Example 2: Adding a user in the command line using flags:

Now the user gets a message saying that "1 contact(s) ready to be saved. Select option 2". This option will write the saved user to a file, that is, it will append the new user to the end of the file contents. Once having done this, it will display a message like this:

Another option hat has been implemented is if the user just wants to see the address list. For that matter, if the --show flag is passed, it will read the file and show the contacts in the list:

This was just a really easy example on how to deal with input arguments with C++. Here is the code of the program, I hope you enjoy it!

miércoles, 20 de febrero de 2013

Mutant Encryption Algorithm

Today's project is more about the same topic of encrypting passwords.This piece of code is aimed to encrypt passwords, but this time it won't return a single character array, but a constantly-changing matrix which contains the password. I am currently working on the decrypting algorithm, which I'm done so far with. As you may deduce from the code, what I do is 'insert' the password character by character into the matrix following this order:

  • First element will go in row 0 and a random column between 13 and 36
  • Second element will go in row 1 and a random column between 13 and 36
  • 'n' element will go in row n-1 and a random column between 13 and 36
Here I attach the file, as always:

And here I show the code, which is really simple:

jueves, 7 de febrero de 2013

Test-Type Exam Correction With Java

Hello everyone!

Today's little project is a simple way of correcting tests with Java. In this piece of code I just defined two possible models or answers, they're all random, but the only thing needed is to update them with valid answers. The length of the test? I just did it for a 10-question test, but it can naturally be extended to the number of answers the teacher may want.

Here's a snapshot:

And the code:

miércoles, 6 de febrero de 2013

A simple function that hides typed passwords in C++

In C++ console there's no way of hiding passwords at the same time we type them (I mean, our password remains visible for everyone who may sit next to us). There's a simple way to avoid this that resembles to what can be easily made in HTML or JavaScript: simply adding a cls command to clear all the console output until that moment and then popping up the same stuff but now with '*' instead.


sábado, 2 de febrero de 2013

Password-Decryption with C++

Hi there!
I just finished the second and last part of my little project called Encrypting&Decrypting Passwords with C++. What I show you today is the other part of the code: how to get the real password from a senseless and non-intuitive string, previously encrypted by the first program. As you may know, there are millions of ways of encrypting stuff like passwords, texts, phone numbers...strings in general. Here I show you what first came to my mind. The current program asks the user to type the encrypted password, and it recognizes whether it went through the simple-mode or advanced-mode encryption way. And that's it, it gives back the original password.

 Here are a couple of snapshots, where user chose simple-mode and the result was a string with just numbers:

and user chose advanced-mode ant the result was a string with weird characters:

Here is the file located on my Skydrive account:

And here is the code:

domingo, 27 de enero de 2013

Password-Encryption with C++

Today's project is about protecting your passwords. There are some powerful programs which are capable of stealing passwords from apparently secure Internet sites. In order to avoid this, I developed an algorithm to encrypt any alphanumeric password given by the user. I am currently working on the decryption algorithm, which is clearly more difficult. The program asks the user to enter the password, and afterwards he is prompted to choose an encryption level (simple mode or advanced mode). And the program generates another password with different characters. As you may notice, the encryption algorithm IS NOT RANDOM AT ALL, so that's why I'm currently working on the other way round code. Here are a couple of snapshots of the program.

In this one, user chose simple mode encryption:

And in this one, user chose advanced mode encryption:

I let you download the executable file from my Skydrive account:

And finally, here's the code. Notice that the encryption algorithm can be anything the developer wants. The more complex it is, the less vulnerable is for possible hacking. If the code was made using any kind of pre-established random functionality, the deencryption algorithm would be really hard. This program and the one I'm into right now are designed to work together: one encrypts, the other one decrypts the first one's output.

New Blog/ Nuevo Blog

Hi there, I just created this blog. As you may have figured out, it is oriented to programming stuff. From now on I'll share my little projects on this site. My other blog is: http://eiger824.blogspot.com. I hope you enjoy it.

Hola a todos! Acabo de crear este blog. Como os podréis imaginar, está pensado para publicar códigos en diferentes lenguajes de programación. Iré compartiendo mis pequeños proyectos y códigos en este blog. El otro es: http://eiger824.blogspot.com . Espero que lo disfrutéis.