Wednesday 7 December 2016

Maximum subarray problem

Problem Statement

Finding a contiguous sub-array which has the largest sum in an 1-D array.

Algorithm

This problem is solved by using Kadane Algorithm. This algorithm is a linear time algorithm.

Wednesday 2 November 2016

Print the number of substrings which are a Palindrome

Q: Given an input string, find out the number of substrings for the given strings which are palindromes.





Solution Strategy : Brute Force
Language : Python


Tuesday 1 November 2016

C++:Printing the kth smallest suffix for a string

Prequisistes

  • Stl vector
  • std::sort() for vector
  • Pointers

Code 

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

Saturday 29 October 2016

Thursday 27 October 2016

Remove Unwanted Software from Ubuntu 14.04

I recently decided to remove some of the useless software that comes bundled with Ubuntu 14.04. This included the games.However removing the games turned out to be little tricky, I finally found the answer on a comment in a thread on Ubuntu forums, thus the post.






Monday 24 October 2016

Advanced Linux Commands

Here are a few linux commands that are pretty useful. However no one every bothers teaching you these commands. However, here at Programing Wonders we never leave out such awesome stuff. Like how to create this:

whiptail to create password box






Friday 7 October 2016

How to Dive into Android

Introduction


How to  begin android programing
Android Programing
Recently I dived or rather scuba dived into android. Around three months ago I knew practically nothing about android as far as app development was concerned. Just installing Android Studio on Ubuntu seemed a daunting task. Once the installation was done, looking at the interface of android studio kind of scared me. Around 30 days of resource and knowledge gathering  and I was good to go. 60 days latter I had written a entire app having an interface as good as Whatsapp, OCR and database. In case, you wish for the code, it will be released soon.

Saturday 10 September 2016

Execute Commands at a Specific Time in Linux-"at"

The other day I was reading about Reliance Jio Offers. Most of their plans come with limited data, but during night times you get unlimited usage. The catch is that night time period is only three hours 2:00 am to 5:00 am.

Unless you are either nocturnal animal like an owl, or a bi-phasic / polyphasic sleeper this implies that you cannot use the unlimited night time benefit. While this might be the case for an average user but for expert users(people who read my blog :-P) this is no problem.

Guess what Linux offers multiple ways to solve this problem

  1. Cron : Read about this yourself. I will not be covering this in the current article. This is more suitable for recurring jobs.
  2. At: The at command this is more suitable for one time jobs. This will be covered in this article.
Android also offers this facility. You might need to have root access for this though. I have covered this in one of earlier articles about Tasker.

Ps: I have no knowledge about IOS, Windows , or Mac platform pertaining to this automation issue. So go figure it out yourselves, in case you are using one of these platforms, leave a comment below explaining how you did it. And I will create a new post for the same.

Wednesday 7 September 2016

Identify Mobile Operating System using Python and ADB


Q:Write a Python/Java/C+ program to verify the operating system name and version of Mobile devices.


Note: This program will only work for android devices. (Since Iphones do not have anything equivalent to adb. )No wonder android is the favorite platform when it comes to app development. Android market is also more developer friendly as compared to its ios counterpart.

Errors: In case you get an error about insufficient permission, either edit udev rules or borrow a phone from your friend, having a well known global manufacturer.

OS:Fedora 20 64 bit
Phone: Sony Xperia
Language: Python
Dependencies: Just adb package,No need for sdk
fedora:               <yum install adb>
ubuntu:              <apt-get install adb>

Friday 2 September 2016

Common Logical Errors in C and C++

Today I spent over two hours discovering this stupid mistake in my code.
a=a++;
Thus I came up with the idea to make a cheat-sheet for common programing mistakes. I hope this is useful to you during your practical exams preparations, debugging times and coding competitions. In case, I have not mentioned one of the mistakes that you make just leave a comment and I will add it.

Thursday 1 September 2016

Mondo DB with Java for processing Images


Q:Use MongoDB to process semi structured and unstructured data collections such as Rfid, images, blogs use python/Java MongoDB interface.

Testing Environment


Mongo DB version : 2.6.3
Network : switched LAN(Ethernet)
IDE: Eclipse (Java EE)
OS: Fedora 20 (64 bit )

Finding primes in a range of numbers

The fastest way(yet easy to understand and implement) to test a prime number is Rabin-Miller Prime Test. However, it suffers from two issues:
  • It is suitable for a single number
  • It may give false positives
When it comes to finding primes from 1 to say 10^6. This method is not suitable. Since this method doesn't use any previously generated information. So the program will end up testing each number.

Sieve Algorithm on the other hand, uses previously generated results and works faster when determining the primes in a range.

Here is a code snippet for the same

Friday 26 August 2016

SQL with JDBC

Q: Design at least 10 SQL queries for suitable database application using SQL DML statements:
Insert, Select, Update, Delete Clauses using distinct, count, aggregation on Client-Data sever (three tier).

Use Python for Socket Programming to connect two or more PCs to share a text file.

Os: Fedora 20
Network: Switched LAN(Ethernet)

Note: Program fails to work on Local Area Network. Program works flawlessly on localhost.

While this script works perfectly fine on loop back ie on the same machine, it fails on networks.For some unknown reasons I havent' been able to get this script running of a local network consisting of fedora linux machine despite tweaking with the firewall. I don't get much time to work on local networks and am currently busy with some other endeavors. 

Write an IPC program using pipe using C++ and Python

Q: Process A accepts a character string and Process B inverses the string. Pipe is used to establish communication between A and B processes using C++ & Python

Write a program in Python/C++ to read display the i-node information for a given text file, image file.

Code

 

 

DBMS using connections (Client-application server-Data sever, three tier) Oracle/MySQL (ODBC/JDBC), SQL Joints, prompt.

Created in eclipse(Java EE).

Friday 5 August 2016

How To Securely Store Data

Note : You require knowledge about file recovery to understand this article. In case, you have no knowledge about this, I highly recommend checking out my article on file recovery.

In one of my earlier posts I demonstrated File Recovery using Forensic Tools.
While File Recovery is possible if the file is deleted using Shift-Delete or even if the partition is formated.

This becomes a major security issue if your pendrive held confidential data earlier. Even quick format is not an option.

Using specialized tools forensic experts can manage to recover any data which was stored on pendrive or any other storage device, provided it is not overwritten. In case , it is overwritten the data could still be partially recovered. I had once recovered partially, a few images using Recuva. They don't look like the exact image but just the thumbnails can be pretty informative.

Sunday 17 July 2016

Pulse Code Modulation and Netowrking using QT and C++

Q: Write a program for Pulse Code Modulation and send the data to a server

Introduction

This is C++ code for both the client and the server to implement PCM and netowrking. The Client is a GUI program while server is terminal based.

 

Monday 11 July 2016

Python Script to Recover Deleted Files And Partitions

Ever deleted a file permanently and wished to recover it. Here's a python script designed to do this task in Linux operating system.

Friday 24 June 2016

Magic Sys Rq Key

The Issue


So the other day I was working with Android Studio on my Low Hardware Spec Ubuntu Machine. I decided to build an apk as emulators are simply not an option. But Guess what , my pc used all of the possible RAM and all the possible swap memory and hung(that's pretty rare for Ubuntu!).

I tried opening a terminal Ctrl+Alt+T hoping to kill android studio process. But the PC was unresponsive. This is despite using all the regular optimizations for android Studio that I found on Ubuntu Forums and Stack Overflow.

Any noob would have now headed out towards the power button. If you ever do come across this situation please do not use this approach. This is the last thing you should do, only if everything else fails.

Tuesday 21 June 2016

Python Based Chat Program

This is a simple client-server Program to chat with other users on the Lan. This program largely similar to a chat using nc, easier to use and with a lot of less functionality.

Tested On:
OS: Fedora 20, Ubuntu 14.04 LTS
Language: Python

 Note

While this script works perfectly fine on loop back ie on the same machine, it may fail on a network since you might need to configure the server to accept incoming connections. You might want to check iptables or disable it completely. 

Video

Monday 20 June 2016

Email Header Analyser Using Python

Q:Write a program in Python to analyze email header.

This program simply analyzes a email header stored locally on your machine in a text file and shows information like:
  1. Mime Version
  2. Date
  3. Subject
  4. From
  5. Delivered To
  6. To
This is nothing but a simple file handling and string matching problem. And to make it look insanely simpler, I decided to write the code with the minimum number of lines, and guess what I did manage it in just 15 lines. I did have to remove the exit messages though.

Sunday 12 June 2016

Tasker: Automate Things on Android Phone

Do you wish to make your phone smarter ?
Do you wish to automate your daily tasks on your phone ?


If yes, here is your Answer : Tasker App (Playstore Link)

Tuesday 31 May 2016

Vison 20-20-20 : A bash Script

 20-20-20 Rule


Anyone who spends more than 3 hours before a computer screen in at the risk of suffering from computer vision syndrome.  Currently an estimated 70 million computer professionals are at the risk of suffering from computer vision syndrome
A programmer spends hours before the computer. To avoid damage to eyes and prevent computer vision syndrome , the 20-20-20 rule is suggested by doctors.
The 20-20-20 rule is as follows:

Look at an object 20 feet away for 20 seconds every 20 minutes.

The Issue

It easier said then done. You simply don't remember when 20 minutes have passed. Thus I have taken efforts to help you with the 20-20-20 minute rule. I have created a bash script vision20 to help with this.

 

Monday 9 May 2016

Unable to Test Buffer Overflow Attacks with GCC?

Buffer-Overflow
Stack Smashing
Recently I was trying to attempt a buffer overflow attack when I came across Stack Smashing Detected. In case you don't know what this is, don't bother reading further.

Looks like GCC has new cool feature which protects codes from buffer overflow attacks. So to some extent even if a programmer doesn't check for a buffer overflow error GCC still might check it and protect the code.


Wednesday 20 April 2016

Display Real Time Clock TSR in Dos


TSR:

Terminate but Stay Resident Program is a type of assembly program which stays resident / or occupies memory on ram so that it can be executed upon interrupt.
TSR is actually one of the best ways to ways to write viruses. The best part is that until the computer is restarted the virus can stay in the memory.

It consists of three sections:-
which you are supposed to find out.

Problem Statement in Layman Terms
You have to display the time on screen using a TSR.

Tuesday 5 April 2016

32 bit ALP To find length of entered string

Q: Write an ALP to find the length of a string entered by the user.

Assembler: NASM
Debugger: GDB
OS: Ubuntu 14.04 LTS

Code

;Author:-Abhishek Vilas Munagekar

32 bit ALP:Reading 32 bit numbers and printing them back

Q: Write an x86 ALP to read 10 32 bit numbers. Store these in an array. And print them back using various system calls.

64 bit ALP to print Hello Word

Q: Write a 64 bit ALP to print Hello word.

Assembler : NASM
Debugger : GDB
OS            : Ubuntu 14.04 LTS

Assembly Language: Finding the largest number

Q: Write an ALP to find the largest number in a given set of  numbers.


Assembler: Nasm
OS : Ubuntu 14.04 LTS(64 bit Linux)

DAC interfacing with 8086

Q: Write a ALP to interface DAC with 8086.

Software: Minicom
OS: Fedora(Linux-64 bit)

Linux Shell Scripting: Lowercase n Uppercase

Q: Write a shell script for manipulating the case of input text.




C Program for Fork in Linux

Q: Write a program in C for linux fork system call. Also show zoombie and orphaned processes.

The use of fork system call is displayed using the following two programs


Friday 1 April 2016

Monday 28 March 2016

Interfacing of 8251 with 8086 (with Detailed Comments)

Q: Write an ALP to interface 8251 with 8086. Transfer some data from 8086 memory at some location to another location in the memory through 8251.

OS: Fedora-64 bit(Linux)
Software: Minicom

 

Interfacing of 8253(Programmable Interrupt Timer) with 8086(Detailed Comments)

Q: Write an Alp to interface 8253 with 8086 in all the different modes

Os: Fedora-64 bit<Linux>
Software: Minicom

ADC : Interfacing with 8086 (with detailed comments)

Q: Write an Alp to interface ADC with 8086

Os: Fedora
Software: Minicom

Sunday 27 March 2016

Keyboard and display controller:Hardware Interfacing(Properly Commented)

Q: Write a ALP to display the word Hello using keyboard and display controller.


Operating System: Fedora -64 bit
Software Used : Minicom

Friday 25 March 2016

Cracking Open Naively Protected Binaries

One of the simplest way to protect an executable is password protecting it . In this method you use a simple if-then-else construct to check if the entered password matches a predefined value.

puts("enter password");
scanf("%d",&pass);
if(pass==4568)

Event though this way may seem secure, since after compilation this password will be converted to one's and zeros inside the binary file, this is not the case.
A simple disassembly will reveal the true password.

To prove my point I have designed a shell script which cracks passwords from such types of password verifying constructs. This shell file will not work on all naive password check but will deal with some of these types.
Anyone who understands a little bit of assembly along with a little bit a reverse engineering can easily crack variations of this type of password check, even if this script fails.

Tuesday 22 March 2016

B1: Conversion of If-else ladder to overloaded function

Q: You are required to write a C program involving a if-then-else construct and convert it into a C++ program eliminating the if-then-else ladder using overloaded functions.

Text Editor:-Gedit
Language:- C,C++
Framework:- QT(C++)
OS:- Linux-64bit (Fedora)


Friday 18 March 2016

MIL Lab Hack Exposed

 The Hack


Mil-Lab-Hack-ExposedThis hack mostly exploits the fact that assembly illiterates cannot actually differentiate the difference between a binary generated by C programing and assembly language.

The basic prerequisites for this hack are good knowledge of C language and good knowledge of Assembly language. When your assembly code doesn't work you recode the same thing in C language and then replace the assembly generated binary with the binary generated by C code. Once this process is completed , all traces of C programing are erased.

Below is the hack in action....


Thursday 17 March 2016

CPU Architecture Emulation & Sleep Function in QT

 Q:Writing a C/C++ Program to emulate CPU Architecture (Central Bus) Develop register, ALU level GUI to display results.


Language:- C++
Framework:-QT
OS:- Fedora (Linux -64 bit)

Tuesday 15 March 2016

Exception Handling in C++

Create a C++ class named Television that has data members to hold the model number and the screen size in inches, and the price. Member functions include overloaded insertion and extraction operators. If more than four digits are entered for the model, if the screen size is smaller than 12 or greater than 70 inches, or if the price is negative or over $5000 then throw an integer. Write a main() function that instantiates a television object, allows user to enter data and displays the data members .If an exception is caught, replace all the data member values with zero values.

Sunday 13 March 2016

Standard Template Library C++ Database Program

Q: Implement a database program in C++ using STL library. This is an extension of my earlier program.

Code:

Framework:- QT 5.5.1
OS : Linux 64 ( Ubuntu 14.04 LTS)

Linux Hacks 2: Turn Terminal Into a Chat Client

In case you don't wont to leave any history of your terminal chat. Read the previous article about leaving no history on the terminal.


For turning your terminal into a chat client. You need to two commands, the first one is executed on one pc and the other on the pc with which u wish to communicate.

Thursday 10 March 2016

Template Classes C++ & Matrix Operations

Q:- Write a program in C++ using function template to read two matrices of different data types such as integers and floating point values and perform simple arithmetic operations on these matrices separately and display it.

Sunday 6 March 2016

Linux Hacks 1.2 Leave no Trace on the Terminal

Linux-Terminal-Hacks
Linux Hacks
While the earlier article showed you some ways to accomplish this task. I've got a even better way. Do read the earlier article as this will help you in understanding about bash history under Linux.

For those in a hurry, here's ur way...


Saturday 5 March 2016

Perl Program for Counting Number of Lines, Characters and Occurances of a Word

Q: Write a Perl Program to find the number of occurrences for a given word in a text file. Also display the number of characters, words and lines in the file.

Friday 26 February 2016

Linux Hacks 1.1: Leave no Trace on the Terminal

  1. Are you doing something you are unauthorized to do? 
  2. Are you using the terminal?
  3. Do you want to leave no trace on the terminal?

If the answer is yes here's the article. For those who are in a hurry. Here's your command

Sunday 21 February 2016

Virtual base Clases- C++ Marks Database

Q:-Design a C++ base class consisting of the data members such as name of the student, roll number and subject. The derived class consists of the data member’s subject code, internal assessment and university examination marks. Construct a virtual base class for the item name of the student and roll number. The program should have the facilities.
i) Build a master table ii) List a table iii) Insert a new entry
iv) Delete old entry v) Edit an entry vi) Search for a record

Operator Overloading String Operations in C++

Q:-Write a C++ program to perform String operations
i. = Equality
ii. == String Copy
iii. + Concatenation
iv. << To display a string
v. >> To reverse a string
vi. Function to determine whether a string is a palindrome
vii.To find occurrence of a sub-string. Use Operator Overloading

Code

Framework:- QT 5.5.1
Os :- Linux 64 bit(Ubuntu 14.04 LTS)
Language :- C++

Thoughts on Operator Overloading

I managed to write concise and clear code, despite the fact that I don't like operator overloading. Being a Java Programmer I prefer a.add(b) constructs as against a+b .

Concave Polygon

Q:- Write a program to draw a concave polygon in C++.

Framework:- QT
Os :-Linux 64 bit (Fedora)

Code

It is a simple program which draws a polygon when the draw button is clicked. The entire program is hard coded ie.., doesn't accept user inputs

Tuesday 16 February 2016

2-D Java Game Obstruction

Introduction


  1. Obstruction is a 2-D Tile (Grid ) based strategy game developed by me. This Game  was invented by László Kozma <(Lkozma@gmail.com ),a Roman Mathematician.
  2. Obstruction is a fine mixture of simplicity and strategy , a great game to workout your brain. Can you think ahead of your friends.
  3. Obstruction combines the need to think ahead in Chess and the simplicity in Tic-Tac-Toe. Try it out today
  4. Check the video. This is the game under development as of 6th March.

Objective

Your objective is simply to make the last move.

Game Play

  1. To make a move Click on a tile to block it and it its neighbors .
  2. If no free tile is available for your opponent you win.

Friday 12 February 2016

Mean-Variance-Standard-Deviation-Assembly Language-With-Detailed-Comments

Q: Write an ALP to find out the mean, variance and standard deviation for a given set of numbers.



Floating point instruction seem to be pretty hard to grasp, especially if you are using them for the  first time. While coding a solution to this problem, often I found myself opening the Intel ia64 manual confused about the end result of an instruction. Thus I decided to comment the code in detail ,so that readers don't find themselves in a similar situation.

In case you need to refer to the manual here's the link:-

Booth's Multiplication Algorithm -GUI C++

Q: Write a program in C++ to demonstrate booth's multiplication algorithm for 8 bit numbers.

Code:-
Framework:- QT 5.5.1
Language:- C++
Operating System:- Linux 64 bit(Ubuntu 14.04 LTS)

Wednesday 10 February 2016

Demonstration of Paging Tables using Assembly Lanugage

This is a demonstration of the concept of paging using assembly language. Here each page has been declared as an array. And address variable(add) denotes the address which is to be reached. This is assumed to be similar to linear address. This is to be translated to physical address using the concept of paging.

Saturday 6 February 2016

15 Puzzle Game In C

Note:- This is the first game that I wrote and is definitely poorly written code.This is a code written by me in two days after reading a C book for five days after my 12th with absolutely no formal training in programing. In fact I would be commenting on the mistakes that I made during coding of this game so that you don't make them. Is this code worth reading then? Yes definitely. The text based graphics and scan key events might be worth reading!

Friday 5 February 2016

ALP to multipy numbersWITHOUT MUL instruction

Q: Write a ALP to multiply two 8 bit numbers using Shift-Add Method and Repeated Addition Method. Accept the numbers from the user. Make the program a menu driven one.

Personal Database C++ GUI Application

Q: Create a Personal Database. Provide facility to delete, add and search for people in the database. The following things must be implemented in your code.
  • Copy Constructor
  • Inline Functions
  • Destructor
  • Default Constructor
  • Parameterized Constructor

Thursday 4 February 2016

Complex Numbers-C++ GUI Application

Q: Write a C++ program for implementing basic operations on complex numbers. Use of operator overloading is expected.

Code

Framework used:- QT
Os:- Linux 64bit (You can use the executable directly if you have this os else compile it)

Wednesday 3 February 2016

Miller Rabin Primality Testing Algorithm in C language

  1. This algorithm is a monte carlo algorithm used for testing whether a given number is a prime or not. 
  2. This works much better than fermat's theorem.
  3. This algorithm is likely to give false positive in case of Carmichael numbers.
  4. The code implementation given below will not work with any number less than three.
  5. This code contains a large number of commented out printf statements which i added during debugging. However I decided against removing them as I though it might help some one whose trying to understand the working of the algorithm. 

Monday 1 February 2016

Powerset Generator Recursive Algorithm Python

 Q:Write a python program to generate powerset for given set of elements.

Truth Value Generator-Recursive Algorithms-Python

Q:- Write a Python Program to generate all possible truth values for a given number of boolean variables

Tower of Hanoi-Solution

python-tower-of-hanoi The Game

Tower of Hanoi is a puzzle game. Your objective is to move disks from one tower to another tower. You initially have 3 towers of which two are empty and one(say tower 1) contains n disks. These n disks are all of different sizes. In tower 1 they are present in definite order- the largest at the botttom and the smallest at the top. You can only move one disk at a time. The rule is that you cannot place a bigger disk on a smaller disk. This relocation of disks needs to be done in minimum number of moves.

Saturday 30 January 2016

Finding Average of Numbers-Assembly x86

Q: Write an ALP (Assembly Language Program) to find the average of hexadecimal numbers stored in an array.

Friday 22 January 2016

Two module String Operations ALP

Q:- Write an ALP for String Manipulation Operations . Store the string in data set of one module and write far procedure in code segment of the other module for performing the string operation. Operations to be performed are as follows:-
  • Concatenation
  • Occurrences of a sub-string in a string
Create .obj files of both modules. And link them to create an executable file.

Thursday 21 January 2016

Wednesday 20 January 2016

Circle Drawing in C++

Q: Write a C++ Class for a circle drawing inheriting line class.

 

String Operations in Assembly Lanuguage

String Operations
Q:- Write a 64 bit ALP to perform String Operations. The program should be menu driven with the following options:-

  1.     Length of String
  2.     Reverse the String
  3.     Palindrome Test



Tuesday 12 January 2016

Device Management- Mounting and Unmounting using Shell Scripting

Q:- Write a shell script to mount and unmount devices using shell scripting. Also display the list of devices currently available to the system.

 

Bash Scripting-Adding Users

Q: - Create a bash script for adding a user and modifying access rights

Book Shop Program

Q:-   A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays the book details and requests for the number of copies required. If the requested copies book details and requests for the number of copies required. If the requested copies are available, the total cost of the requested copies is displayed; otherwise the message “Required copies not in stock” is displayed. Design a system using a class called books with suitable member functions and Constructors. Use new operator in constructors to allocate memory space required. Implement C++ program for the system.

Friday 8 January 2016

Thursday 7 January 2016

Weather Report Program in C++

This is a Weather Report/ Weather Forecast Application written in C++ .
It is a GUI Application Written in QT.


Question:

Create a class named weather report that holds a daily weather report with data member’s day_of_month, hightemp, lowtemp, amount_rain and amount_snow. The constructor initializes the fields with default values: 99 for day_of_month, 999 for hightemp,-999 for lowtemp and 0 for amount_rain and amount_snow. Include a function that prompts the user and sets values for each field so that you can override the default values. Write a C++/Java/Python program that creates a monthly report. Menu driven program with options to Enter data and Display report. Report Format
Day Amt_Rain Amt_snow High_temp Low_temp
--------------------------------------------------------------
Avg

Memory in Java

Q:-Write a program in Java. To find out memory statistics available for Java Virtual Machine.




Drawing a Line with Different Line Styles

Q:Write a program in C++ to draw a line with different styles thick, thin and dotted. Accept the start point and end point coordinates from the user.

Start-up Scripts Bash

Q:- Write a startup script using Bash Scripting

Line Drawing using DDA and Bresenham

Q:- Write a program to draw line using DDA or Bresenham algorithm. Accept values for the 2 endpoints as well as the input for colour. Inherit a class and overload the functions for DDA and Bresenham.

Wednesday 6 January 2016

Block Transfer using Assembly Language-64 bit

Q:- Write a 64 bit assembly language program to implement the following operations:-
  1. Non-overlapped with string instructions
  2. Non-overlapped without string instructions
  3. Overlapped with string instructions
  4. Non-overlapped with string instructions