Skip to main content

Posts

Showing posts from 2017

Amazing Word clouds using python

Ever wondered how word clouds are generated from a big text corpus? In this post we learn how to make interesting word clouds using simple natural language processing and python. What are word clouds? Word clouds are a way of representing some of the most important words or some of the most occurring words from the big text corpus. In this post we will consider the some speeches by George Bush as our test corpus and make a word cloud from the words that occur the most in the speeches. Steps taken Load the speeches and store them in a variable Remove all the stopwords, stop words are words like 'the', 'and', 'this' and they can be removed for our current purpose. Remove all the punctuation's Construct word cloud consisting of 100 most frequent words and save the image Lets have a look at the code The above code produces the following image as the output Now, the above code produces a simple image, we can mask and try to make our wor...

Vigenere decipher process

In an earlier post we discussed a method to encrypt a string using Vigenere Cipher, in this post we see the method to decrypt the encrypted message. The  Vigenère cipher  is a method of  encrypting   alphabetic  text by using a series of interwoven  Caesar ciphers  based on the letters of a keyword.  It is a form of  polyalphabetic substitution . Even though the vigenere cipher is easy to understand and implement, for three centuries it resisted all attempts to break it. In order to encrypt a given message, a table of alphabets can be used, termed a  tabula recta , The following is the image of the Table. the above table   consists of the alphabet written out 26 times in different rows, each alphabet shifted cyclically to the left compared to the previous alphabet.  At different points in the encryption process, the cipher uses a different alphabet from one of the rows. The alphabet used at each point depe...

Encrypt files using Vigenere Cipher

In this post we discuss a method to encrypt your files using  Vigenère Cipher . The  Vigenère cipher  is a method of  encrypting   alphabetic  text by using a series of interwoven  Caesar ciphers  based on the letters of a keyword.  It is a form of  polyalphabetic substitution . Even though the vigenere cipher is easy to understand and implement, for three centuries it resisted all attempts to break it. In order to encrypt a given message, a table of alphabets can be used, termed a  tabula recta , The following is the image of the Table. the above table   consists of the alphabet written out 26 times in different rows, each alphabet shifted cyclically to the left compared to the previous alphabet.  At different points in the encryption process, the cipher uses a different alphabet from one of the rows. The alphabet used at each point depends on a repeating keyword. Now let us consider an example...

Counting sort Algorithm

 Want to sort numbers in a given range? Use Counting sort algorithm. Counting sort is a integer sorting algorithm, It is a non-comparison sorting algorithm as it does not compare different elements rather it uses index of elements and their count while sorting them. Counting sort is a linear sorting algorithm and must be used when elements are in a given range and variation in the elements is not much. It simply operates by counting the number of occurrences of  different elements in a given range, as it is a linear sorting technique it has time complexity of   O(n + k) where 'n' is the number of elements in the array and 'k' is the number of elements between max and min elements. let us consider the below example,  let the array of numbers to be sorted be  arr = {1,3,2,1,3,3,2} here, n = 7, min = 1, max = 3 hence k = 3 now we create a array that holds counts of all the elements, 1 has occurred 2 times, 2 has occurred 2 times and 3 has o...

Quick Sort Algorithm using Recursion

Quick sort is one of the most important and widely used sorting algorithm. Quick sort is a very efficient algorithm which if implemented well can run two to three times faster than its competitors merge sort and and heap sort. The algorithm is a divide and conquer algorithm. The algorithm works by selecting a pivot element, this pivot element is usually the first element and choice of the pivot element affects the running time of the algorithm. The algorithm is basically to select a pivot element and then moving all the element less than the pivot element to its left and all the elements greater than pivot element to its right. Then we divide the array into 2 parts, one on the left of the pivot and other on the right of the pivot and then pass these 2 arrays to the algorithm for further sorting. Algorithm : Choose a Pivot element. Take 2 variables left_marker and right_marker excluding the pivot element. Set left_marker as the first element of the array Set right_marker as the...

Installing python modules without pip

Ever wanted to install python modules, but you were unable to do it using pip install command, or simply wanted to do it using python, if so then this is the post you want to read.  pip module is now by default installed when you install the latest python, if you want to install multiple python modules you can either enter pip commands in command prompt or terminal or make a batch file, In this post, we will see how to install all the modules that you want by executing a python program. Lets look at the code,  In the above code you can simply put the modules you want to install in the list and execute the code. You might also be interested in  Data Encryption using Caesar Cipher Data Decryption using Caesar Cipher LCM of 2 numbers Anagram Strings Double Linked List Finding Middle node in a Linked List Infix to Prefix Conversion

Data decryption using Caesar Cipher

In the previous blog post we discussed about Encryption of a file using Caesar Cipher, in this post we discuss a method to decrypt the same file. If you want to view the previous post on Encryption using Caesar Cipher click HERE . Decryption is a process of decoding the encrypting the encrypted file, to do this we need to know 2 things, the first is the method of encryption and the second is cipher key which in this case is our shift value. once we know these things we can start deciphering the files.  As caesar cipher is a substitution cipher, shift value decides which value is replaced with another value, in encryption we replace each letter by the letter to its right by shift value position, hence now we need to do the opposite, we have to replace each letter by the letter to its left by shift value positions. So for shift value of 3 we have, Plaintext :          ABCDEFGHIJKLMNOPQRSTUVWXYZ  decipher text :     XYZ AB...

Data encryption using Caesar Cipher

In this post we will discuss what is cryptography and how can we encrypt our files using Caesar Cipher. First Things first let us first understand the what is cryptography, according to wikipedia, " Cryptography  is the practice and study of techniques for  secure communication  in the presence of third parties called  adversaries" Simply stated it is passing messages between 2 user using a channel that is not secure yet the intruders trying to get steal information will not be able to understand messages directly as the messages are encrypted. In order to encrypt a message, we change the contents of message such that only the intended receiver of the message is able to decode it. Let us now discuss Caesar Cipher, sometime also called as shift cipher is a ciphering technique that is one of the most simple and widely known techniques of encryption. This technique uses a substitution technique in which for each letter in our message we have a letter...

LCM of two numbers

In this post we discuss a method to find out LCM (least common multiple) of 2 numbers, LCM of 2 numbers is the least number that is divisible by 2 numbers. for example, if we consider 4 and 5 then their LCM is 20. Though there are a lot of methods to find LCM of 2 numbers here I will focus on find LCM using GCD of 2 numbers. Consider 'A' and 'B' to be 2 numbers so we calculate LCM  by using the below formula The product of the numbers is equal to the product of their GCD and LCM.  A * B = GCD(A,B) * LCM(A,B) If you want to know about GCD of 2 numbers then follow my post on GCD Here. In the following programs, we first find the GCD of 2 numbers and then divide the product of two numbers by the GCD to LCM of the numbers. C Program C++ Program Java program Python Program C Program C++ Program Java Program Python Program You might also be interested in  Anagram Strings Double Linked List Finding Middle node ...

Check is given strings are Anagrams

Checking if 2 given strings are anagrams or not is one of the most common and easiest interview questions which is often asked in interview coding rounds. In this post we discuss method to identify if 2 strings are anagrams or not. 2 strings or words or phrases are said to be Anagrams if they are formed by rearrangement of same letters. For example we consider "HOST" and "SHOT" they are formed by rearrangement of letters H,O,S,T. We can find a lot of such examples. Let us now discuss the method to check if 2 strings are anagrams. First we remove all the white spaces from the given strings. For strings to be anagrams the length of the strings after removing white spaces must be same, so we compare lengths. if the lengths are equal then we move forward. else we stop as the length of the strings must be same. The next step is to convert the string to lowercase, this step is optional and you can choose not to do it depending on your requirement. Then ...

Binary Search Algorithm

Binary Search also known as Algorithmic or binary chop is a searching algorithm that searches for a element in a sorted data structure. Binary search is a searching algorithm that searches the required value by comparing the target value with the middle value of the array. The following is the algorithm for binary search implementation Step 0 : Sort the array using any sorting algorithm (I am using bubble sort in the below program) Step 1 : Initialize first = 0 and last  = list.size() - 1 Step 2 :  while first < last and the element is not found calculate mid = (first + last) / 2 Step 3 : Compare target value with middle element Step 4 : if the middle value is greater than the target value then target value lies on the left side of the middle value do goto step 1 with last = mid - 1 Step 5 : if the middle value is lesser than the target value then target value lies on the right side of the middle value do goto step 1 with first = mid + 1 Step 6 : ...