Recursive Function in Java

Hello everyone;
Today I’d like to talk about “Recursive Functions” in Java by giving an example. The definition of Recursive function is the function that calls to itself. By simple Google search
you can find loads of websites that explain Recursion in more depth. However, I’m not going to be repetitive as I’m sure you can all use Google :)
I’m interested in security software so, let’s say that we want to write a Password Cracker application that uses brute-force method to crack our Hash. That means trying every single possibility or combinations until we get the match. Assuming that we know the encryption algorithm (MD5, SHA1,…etc.) but we don’t know the length of the Password. Therefore, we need to test all the combinations. For example if the password is “DDDD” we need to try all the possibilities from “A,B,C,D…AA,BB,CC,DD,….AAAA – DDDD” meaning we have 4^4=256 possibilities. (When it comes to long passwords, this method is not really effective; I will explain this at the end).
Obviously, the first thought would be to insert a “for loop” for character generator. This won’t be really practical since we don’t know the length of our Password, that’s where Recursive function would be the best solution.
Here is a Java code that uses all English alphabets and numbers to test all possible combination for a value that has five characters:

public class CharGenerator {
    //All the English Alphabet and numbers
    private static String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+
    private static List list = new ArrayList<>();
    //Recursive Function
    public static void generate(String string, int length) {
      if (length == 0) {
        System.out.print(string + ", ");
      for (int i = 0; i <chars.length(); i++) {
        generate(string + chars.charAt(i), length - 1);
    //Main Method
    public static void main(String []args) {
      System.out.println("[ ---Starting--- ]");
     //Length of the password
      for (int i = 1; i <6; i++) {
       generate("", i);


D:\Programming\Java\NetBeans\Testing\build\classes>java CharGenerator
[ ---Starting--- ]
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,..... 999999

When the passwords are combinations of numbers, characters and special characters, this method is not really effective. (I have used it to crack a password before though but I was lucky and password was only 4 characters long). However, what if we have more than one computer and we can split the cracking tasks among network of computers and each individual computer can also divide it to smaller tasks (Threads) and they can all communicate with one another. (Hint: just pay more attention to the “generate” method). I’ll let your imaginations do the rest 😈

Thank you and good luck :-)

Comments Off on Recursive Function in Java more...

IP address Blocker application

Hello everyone,

My servers have been under brute-force attack  by different IP addresses around the world (mostly China). So, every now and then I try to block the malicious IP addresses. I wrote a console base application in Java while ago to analyze Linux SSH and Apache log files (auth.log or message.log depending on what distribution you are using) and report the possible brute-force attempts.

However, for personal interest I decided to improve that application and create new GUI application in Java to analyze log files in order to get the IP address’s origin and to make life simpler by automatically generate IPTABLE’s filter or .htaccess filter file, if I decide to block them :)

Below, there are couple of screen shots of the application, I couldn’t think of any good names so I called it JIpBlocker. It’s very simple to use, all you need is a log file, so I’m not going to write any guidance for it.

Main view

logFile locate


 Download Link

This is an Open Source application so please feel free to modify or do whatever you want with the code :) I have uploaded the project repository to GitHub and can be found here. You can also participate to develop it even further if you have some spare time.

If you have any questions or concerns, please don’t hesitate to contact me.

Many thanks :)


Comments Off on IP address Blocker application more...

Copyright © 2008-2015 All rights reserved.
Jarrah theme by Templates Next | Powered by WordPress