Wednesday, September 14, 2016

Snort Installation in Windows and Linux


Windows
 
There's nothing much to talk about. This video tells it all :

https://youtu.be/RwWM0srLSg0

If you don't prefer videos and rather prefer text, then the written form of the instructions that the above video gives is here :

https://www.securityarchitecture.com/learning/intrusion-detection-systems-learning-with-snort/installing-snort-on-windows/

Linux [ Beware. It's tedious. ]

Weird that I installed this software in Windows. I hardly use Windows these days. But I checked out the above video and the guy used Windows and I just followed it and did the whole the thing. But if you are a Linux lover, and use a Linux distro, here's a written tutorial on how to install Snort in Ubuntu :

https://www.securityarchitecture.com/learning/intrusion-detection-systems-learning-with-snort/installing-snort-on-linux/

But Beware. I see a lot of complications in the first page (of the above link) itself. I mean, the way the installation goes. Like they use Virtual Machine to install Ubuntu in it, but you don't have to if you have some Linux distro installed in your PC, and then they get Snort by compiling source files of Snort. And then there are lot more steps. I am yet to check it out the whole thing. Still, I just thought I should share the link. But then, don't do it if you aren't up for tedious tasks.

Saturday, September 10, 2016

DES Implementation


To know about how DES works in a nutshell, check this video :

https://www.youtube.com/watch?v=3BZRBfhpIb0

And here is a link to know how to implement DES and it helps you with some examples to check if your code works properly.

http://page.math.tu-berlin.de/~kant/teaching/hess/krypto-ws2006/des.htm

There are many lookup tables in this algorithm, don't make any mistake in initializing them. These tables are mentioned in the above link whenever they are used in between computations. But to check out all the lookup tables at once, check this Wikipedia page :

https://en.wikipedia.org/wiki/DES_supplementary_material

And the Wikipedia page for DES is informative too, it has some good diagramas to represent some computations. Check it out :

https://en.wikipedia.org/wiki/Data_Encryption_Standard#Description

SHA1 Hash Implementation


If you have done MD5 implementation, then SHA1 is quite easy with some small tweaks. Like, SHA1 is fully big endian, unlike MD5, and there are some different compression functions and stuff. That's it.

To know how to implement SHA1 you need to check the official documentation :

https://tools.ietf.org/html/rfc3174

That is the best source, obviously. And there are two ways to implement it, you can choose one and implement. The only difference in the two methods is space and time complexity.

And if you want a good pseudo code, Wikipedia has one for Method 1 of the documentation :

https://en.wikipedia.org/wiki/SHA-1#SHA-1_pseudocode

That should be enough to code SHA1. For any queries, mail me.

Sunday, September 4, 2016

MD5 Hash Implementation


Hey guys! I recently coded the "MD5 Hash" exercise, so I thought I will skip some exercises and share some info related to MD5 and then come back to other exercises and post them later.

So here you go, these are some Cool links I found out.

The official documentation : https://tools.ietf.org/html/rfc1321

I recommend you read the above link, fully. If the font's not readable,
try this link : http://www.fastsum.com/rfc1321.php

Both the above links contain the same info.

And here's an example of how the hashing works on "Hello World!" string.

https://www.scribd.com/doc/35954574/MD5-With-Example

It's really good, in the sense that it helps you know the results of each "round" ( read the documentation to know the jargons. :P) and that way, it will help you debug your code if there's any problem.

***END OF POST***

BIG Note :P :
 
It's not an easy thing to code MD5. But you should (actually, you must!) try it. And stop getting code from others :P Besides, there are more tough exercises like this one. Like SHA1, RSA etc. At least try one of them. Don't get the code for all of them. And Trust me. It will be really hard to understand your friend's code! Sadly you will be cursing your friends (for eg me :P) for writing big, tough or crazy code. Sometimes no one can help writing tough code. So, don't curse them :P And by the way, it's more tougher to understand the code when you don't know anything about what the concept of the exercise is. So, I 'recommend' you try coding the exercises. May be even group up with friends and code modules of the exercise. This way everyone gets to know the exercise. But don't code one whole exercise and ask your friend to code another whole one. It never helps :P

Friday, September 2, 2016

Rail Fence Cipher and Row Column Cipher

Caesar Cipher and Playfair Cipher


Hey guys! The blog is back with a Bang! :D

Let's start with Cryptography Lab stuff. For all ciphers, their corresponding Wikipedia pages have enough information to learn from and the Lab exercise Q PDFs also have enough info. But sometimes, the info is wrong, beware. Anyways, even though so much info is present, I will still share some specific sections of Wikipedia articles and some videos to help understand stuff. Makes the task much easier than reading the whole Wikipedia article.

Caesar Cipher : Wikipedia Page is more than enough. :P https://en.wikipedia.org/wiki/Caesar_cipher

See the example too, of course! https://en.wikipedia.org/wiki/Caesar_cipher#Example

Plafair Ciper Explanation : https://www.youtube.com/watch?v=quKhvu2tPy8

To see another example for Playfair Cipher, see this :
https://en.wikipedia.org/wiki/Playfair_cipher#Example

Saturday, July 2, 2016

Aritificial Intelligence Seminar - MYCIN, An Expert System


These are the files that I used and other files that got from the other class, for my Seminar on MYCIN.

Seminar PDFs

Sunday, April 24, 2016

Date Picker Dialog in Android


This dialog "only" gets Date as input. Not time too. Code and screen shots are in the PDF.

Code in PDF

Compiler Lab - Control and Data Flow Analysis Code and Theory PDF


Most of the variable and structure names are sensible ones. Except for a few, which are given below. And for size variable of an array, mostly I have used "size" as a suffix. And "no" means number. Just saying.
Name and meaning :
dno - definition number
bno - block number
defblockmap - mapping of definition number to their corresponding block numbers
definitionmap - mapping of variables to a number of defblockmap
globalno - total number of definitions in the program, also the size of the kill, gen, IN, OUT sets.
The theory for the exercise is also attached. I just understood it as a math problem and coded using the equations and logic. No idea about the exact theory. Alfre Aho book should help you in that.
Some confusions people face are about Kill, Gen, IN, OUT. These are sets. And the maximum number of elements they can contain is the total number of definitions in the program, which is globalno in my code. And since that is the maximum number, these sets are represented using bit vector representation. So, Kill is denoted by n bits, where n is the globalno value and each bit denotes a definition number of the program. And if a definition number is present in that set, then it's corresponding bit is set to 1 or else it is not present, it is set to 0. You should know this to do the Union and Subtract set operations properly on these bit vectors.

Code and Theory 

All the Best ! Quick Tips for Sem Lab - Android and Compiler


All the best for the Semester Lab exams! Quick points to keep in mind while coding in lab :
1. Try to be awake while coding. And don't get fatigue. Try to be calm, and not frustrated ( I m one to say. ) and avoid mind blocks. Drink water in equally spaced intervals to keep the brain cells active and not dehydrated and it helps to keep the body hydrated too. ( Actually, if you feel thirsty, you are already dehydrated. )
2. You Must be awake while debugging the errors in your code. And I will try to put up a tutorial on how to find out the part of the code causing segmentation fault in the C programs using GDB - GNU Debugger ( Google it ).
3. While debugging logical errors, most times, we just skim through the code and follow the flow of control starting from the main in the case of a C program or the start symbol in the case of a yacc specification. I suggest you do some paper work using pencil while debugging. It has helped me out in most cases. Sometimes you will feel there's nothing to write down and find problems. Well, paper work has helped me even in such cases (even recently) ! Write some crap, but write, then see it, then think, and you will find the logical errors. It actually helps you focus better on what is happening though you might not have written every detail in your paper, and it keeps up your concentration. And this way, you won't over look stuff too. Trust me. Paper work, any day. Just be quick though :P because it takes time, but it's worth it, instead of executing the whole code in your mind palace.
4. I usually don't advice about such stuff, but this time, I think I will. Code in versions. Especially all the big codes you do in compiler lab, well, you better code in versions and test each one. Let's say you have to do YACC, first complete LEX and test if it works fine for BOTH good And bad input. Yes. Then move on to code YACC and test if it works together. It takes a bit of time, but not much, and again, it's worth it.


Mail me if you have encountered errors in the past that you were not able to solve and still remain unsolved. Errors like the weird looking "unmatched rule" in LEX specification even though you think your specification looks perfectly fine, and then the YYSTYPE related errors in YACC - LEX specifications.
And you can even ask about Android stuff. In fact I heard crazy errors that were declared as "Emulator problems. It ain't working." . Actually, those errors arose because of wrong code, but the emulators and Android Studio were blamed. I don't know what to say. But yeah, if you don't know what is happening, well, just blame the computers and try to get away with it, but beware, if the teacher says try in another computer and stuff, and if your code still doesn't work, well, you are caught.
Well, that was big, did you skim read ? :P Anyways, for anything else, just mail me.

Saturday, April 23, 2016

Android Basics For Lab, Part 1


About the basics of Android, part 1.

GDB Tutorial to find Code causing Segmentation Fault in C/C++ programs


Basically, you have to compile your program like this :

gcc -g test.c -o test

where in, "test" is the output file name. And -g is used to put debugging information too in the "test" file. Read the above Tutorials Point link to know more about it.
So, you execute the program like this :

./test

Later, if you get segmentation fault, just do this :

gdb test

Then a prompt comes up, type

r

This will run the program, and it will run with debugging mode on I guess. So, when there is a segmentation fault, it will show you the line number and the line of code itself. For example, see the below screen shots :
I am writing a code to basically dereference a null pointer.



When I type "r" command [ Look for "(gdb)" - the prompt, in the screenshot ] , the program runs, and you see the "starting program : ..." message and you see the segmentation fault and where it was received.


And then I type "q" command to quit and say "y" to confirm it. Check the Tutorials Point link to find out more GDB commands. But these two commands should be enough to find out the code causing segmentation fault.



A friend asked if gdb is installed in our lab computers. Well, I think it's a very general package like gcc, and when I tried "sudo apt-get install gdb" and the same for gcc, the prompt said it is installed automatically under some package named "linux-image-extra-xyz.abc.
pqr-generic" something, as if they are all in a single basic general package. So, I think it should be installed. So, just remember these commands and try it out in your programs in case you have segmentation faults in them.

Sunday, April 17, 2016

How to create a "simple" Android Project


Creating a new project is easy. But sometimes you might use unnecessary templates and complicate it. Here's a video to explain it and to tell that only "Blank Activity" must be used to start from scratch and for simple layout and design and not "Material Design".


Friday, April 15, 2016

Buttons and Button Clicks


Running some code on a button click is actually an easy thing to do, and there are many ways to do it. If you are not comfortable with the way you are currently used to, you may try this method.

When you define Buttons in the XML Layout, using the Button tag, just include an extra attribute, android:onClick to it, for example, like this :

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:id="@+id/bStart"
android:onClick="MyClick"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />


If you see, I have written the value for the onClick attribute as "MyClick". This basically means, execute the function named MyClick which is present in the Java Code for the corresponding activity (screen) for which the layout has the button tag.

So, in the Java code for the corresponding activity, put this function :


public void MyClick(View v)
{
               int id = v.getId();
         
               switch(id)
              {

                           case R.id.bStart :         
                                                          tvResult.setText("Start button clicked!");

                                                          break;

               }

}

As you can see, the function takes in an argument, which is a View class object. So, this function can be called by any of the Views in the XML layouts, even by a TextView. But we are calling this only from a button, using the android:onClick attribute. Now, when the function gets called, the value of v is assigned accordingly, based on which view (that had this function name in it's onClick attribute) was clicked. And then, you can get the view's id using the getId() method, which, if you don't remember, when you type "v." in your Android Studio, it will give a lot of functions as suggestions. And to get data, most times, Java methods have the get word at the start, so type "v.get" and you should see a list of get based methods, to get data. Now, press Ctrl + Q to see info about the functions, when they are highlighted in the suggestions. Finally, click on "getId()", and you will have "v.getId()" finally. Actually, you can use this method of determining methods, for all cases, and this was just an easy example, where getId() is an easy method name to remember, but still, I wanted to explain how to do it, when you don't know what methods exist and what is possible and what ain't. And if Android Studio doesn't show any suggestions on it's own, while typing ( probably due to some problem, or due to low RAM, consequently, very slow response of the editor ), the shortcut to get suggestions is Ctrl + Space.

Finally, you can use a switch statement to check the id of the view. So, if you have many buttons, all can have MyClick as the function name in the android:onClick attribute and when the function is called, you can identify which button called the function, using the id of the button. So, use R.id.xyz to refer to the id. And then in the switch case statements, execute what your logic is, for the appropriate button.

Tips : I recommend you to write the function first, then put it's name in the android:onClick attribute value in the XML layout. This way, when you type in the function's name in the value, it will show suggestions, about your MyClick function. This suggestion is show only when MyClick method is public. So, don;t forget, it MUST be a public method, else the App will crash, ie it will crash, if the method is private and if it's being be called from the layout.

Comparing with old code and feeling better ( Please don't look at this section if you get confused with too much code ) :

Finally, the best part is, you don't have to use code like this :

buttonStart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          Intent i = new Intent(MainActivity.this,SecondActivity.class);
          startActivity(i);
       }
});

where buttonStart is a Button object. And the above code is messy and tough to maintain and debug and change.

And there's another way, which is slightly better, but you have some extra code. Which is where, you implement View.OnClickListener interface and have onClick() method implemented and also make the buttons listen in the onCreate method, using this code (after referencing the button to it's id) :

buttonStart.setOnClickListener(this);

So, if you have many buttons, you have to put the above code many times. Then, finally, you will have the onClick method, in which you will implement stuff that you implemented in MyClick function. Same old thing. Just the "this" thingy code for making the buttons listen, will be extra code over here. And in this case, if you miss the code to make the buttons listen, the onClick method is of no use.


Verdict : So, finally, use the Custom Click function, which can be triggered using android:onClick attribute concept in XML layouts.

Tuesday, April 5, 2016

Compiler Lab stuff. Material for Lex and Yacc

Why does your lexical analyzer recognize "int" as an identifier ? What is wrong with your Lex code or your computer ? How do you pass a file as an input to your lexical analyzer ?

Why do you get "shift/reduce conflicts" warning ? What is yylval ? What is YYSTYPE ? What is the weird error related to YYSTYPE you got in your program ? Have you included the necessary files ? Have you included them just once or twice by mistake ? Is there a problem in your compilation method instead of the main logic code ? What are the different ways to compile ? Some ways ( options in commands ) work only in Ubuntu and other Linux systems and not in Mac ?
Ever had any of these doubts or thought about these ? If yes, mail me! Teach me! If no, it simply means we gotta learn stuff to know more.

Now, are you worried about Lab models and Sem Lab practicals? Let's be frank, if you are worried, you are worried either because you coded only a few programs, or never coded at all. Or have tons of doubts. Which sounds fine.
My smart advice would be, learn stuff at least at an abstract level, and have enough knowledge in theory to code the main logic. For this you need preparation ahead of models exam. Or if you are the super smart person, you could learn all the code the day before models and Sem Lab practicals.
Back to Lex and Yacc stuff. Below are some articles I found useful. I only read a few of them. Yet to read others.

http://www.tldp.org/HOWTO/Lex-YACC-HOWTO.html

Particularly this :
http://www.tldp.org/HOWTO/Lex-YACC-HOWTO-6.html#ss6.3
Then this ( a famous one in Google results) :
epaperpress.com/lexandyacc/download/LexAndYaccTutorial.pdf

http://dinosaur.compilertools.net/
Two good videos that I saw :
https://www.youtube.com/watch?v=54bo1qaHAfk
https://www.youtube.com/watch?v=__-wUHG2rfM
I will update more, in the future, if I find anything.
Share the material with interested people! :)

Wednesday, February 10, 2016

New Stuff in SSD

Most of you might have heard about SSD (Solid State Drive). It's kind of been here for about 2-3 years now. I got to know about it only about a year ago though.

Here's a Pocket SSD in the market! But costly enough !

https://www.youtube.com/watch?v=7is4jVl49eo
And do you know how SSDs work ? Get to ! While reading some Quora answer recently, I read that SSDs are based on "electronic" technology rather than mechanical tech in the case of Hard Disk Drives(HDDs). It seems SSD is based on NAND Flash Memory or DRAM or others, as mentioned in

https://en.wikipedia.org/wiki/Solid-state_drive
It's like the next gen stuff, which will completely replace HDDs, considering it's speed, and it consumes less power compared to HDDs. You could check more about it if this amazes you!

Tuesday, February 9, 2016

Android First & Second Exercise : Take Form Input and show Output


The first exercise is about getting form input. Input for details like Name, Age etc and the second exercise asks for DOB to be input in a new Dialog box ( for which I used a small deprecated code - showDialog() function ) and also show all the inputs taken from user, in a new Screen (Activity) on the click of "Submit" button and also, the user can clear details on form input screen by clicking "Reset" button.

I have attached the code for the exercise, straight away.

Here it is.

Just extract the code to get a folder, with all the files. Now import this project into Android Studio after closing your current project (by File -> Close Project). While importing, Studio will tell that it's going to change the sdk location to a new one ( because files will have my computer's sdk location ), just click Ok for it and the project should be imported.

I created the above project in Linux Studio. And I m not sure if this will import properly in Windows Systems. I tried importing my Lab folder ( Linux Studio's Folder ) in my Windows System - but I had some problems. Didn't have time to check what the problem was, but it was kinda complicated. Just try importing for now. If it doesn't work out for you too, please ping me asap. I will check on it. I guess I will check about it, before people start pinging me.

And about the code. It's not that easy to understand the code unless you have already read some stuff about Android - layouts and code. Get a friend who knows to code some basics in Android. I m sure you will have some friend. If you don't, use some good tutorial sites and the official site - developer.android.com/develop/index.html

The official site has mentioned (at the end of the this page) some of it's famous video courses available in other sites, but taught by the Android experts from Google.

Other good sites to learn are

www.androidhive.info
http://code.tutsplus.com/categories/android-sdk
www.stackoverflow.com - To debug all your crazy errors! :D

and the list goes on. You can find a few more in DuckDuckGo search engine by Ducking it ( or just Google it as usual ).

Saturday, February 6, 2016

Android App Development Tutorials

This set of 200 videos, is considered one of the best tutorials for Android, for beginners : 

https://www.youtube.com/playlist?list=PL2F07DBCDCC01493A

Of course, you don't have to see all the 200 videos. About 30 - 40 videos should give you a good idea about what to do and how things are done and about what to search for in Google when you are having problems or have new ideas.

And if you have already installed Android Studio, just start from the fourth video, because the first three are about installation. And actually, the above mentioned videos use Eclipse. There will be small differences. And the videos are old, so, there will be some old stuff. Like, there is some Gradle concept in Android Studio, unlike Eclipse, used in the videos. And then, the stuff that are there in a Blank Activity in Eclipse is different from that of the Android Studio latest version based Blank Activity Project. And sometimes, the layout designs are slightly complicated too.

I really don't recommend you to learn such complicated stuff at the start itself. I usually ask people to always use Eclipse first. But, unfortunately, it is not available as a bundle in the official site. Only Android Studio is available, so, I can't help it. But if you want, you can get it from me and try, for a good start and then move to Android Studio later.

For any queries, just mail me. I will try to clarify it if possible. Or I will use my favorite site - www.stackoverflow.com, which you could use too !


Tuesday, February 2, 2016

New Trends in AI

I recently read this article about a research in Artificial Intelligence, about how an algorithm makes computers "learn" stuff like humans. Just some inspiring new trends and research in AI, to boost up your thoughts about it.

http://www.gizmag.com/artificial-intelligence-algorithm-learning/41448/

Monday, February 1, 2016

Installing Android Studio

Installing and using Android Studio is pretty straight forward in WIndows. It is almost straight forward in Linux too. Just that, in Windows, you click the Application icon to run the Android Studio program, but in Linux, you have to run a .sh (shell) script in the terminal to run the program.

Note before starting : You need JDK installed in your system before installing Android Studio.

Downloading Step

This step is very easy. Just go here

Download Android Studio

And under "All Android Studio Packages", 
  • For Windows, choose the recommended marked exe link.
  • For Mac OS X and Linux, there is only one link, just choose it accordingly.

Installation Step

Now for Windows the exe will do all the installation. And the program icon will appear in the Desktop. For Mac OS X, it's the same I believe. I m not sure though.

For Linux, here is a tutorial for Ubuntu systems. Similar stuff can be done in other Linux distributions too.

https://www.youtube.com/watch?v=qfinKxwYYZs

For any problems please comment or mail me :)

Sunday, January 10, 2016

EBooks for 6th Sem


These are some EBooks that I found just recently. I will keep uploading when I find more! :)

The EBooks include :

1 a. George Coulouris, Jean Dollimore and Tim Kindberg, “Distributed Systems Concepts and Design”, Fifth Edition

1 b. Distributed Systems : Principles, Algorithms, and Systems By Ajay D. Kshemkalyani and Mukesh Singhal
2. Jochen H. Schller, “Mobile Communications”, Second Edition (This is a reference book according to our syllabus. The syllabus actually recommends another book which I couldn't find - Prasant Kumar Pattnaik, Rajib Mall, “Fundamentals of Mobile Computing” )

3. Alfred V Aho, Monica S. Lam, Ravi Sethi and Jeffrey D Ullman, “Compilers – Principles, Techniques and Tools”, 2 nd Edition

4. John G. Proakis and Dimitris G.Manolakis, “Digital Signal Processing – Principles, Algorithms & Applications”, Third Edition* (Syllabus recommends Fourth edition. Will update asap when I get hold of it. )

Sem 6 EBooks