From previous topic about columnar transposition cipher with key. This topic show how columnar transposition cipher without key and how to decrypt..
note: anyone who exactly how its work can correct me. this is how i understand.
Tuesday, October 6, 2015
Sunday, September 27, 2015
Password hash with SHA-1
In cryptography, SHA-1 (Secure Hash Algorithm 1) is a cryptographic hash function designed by the United States National Security Agency and is a U.S. Federal Information Processing Standard published by the United States NIST. SHA-1 is a member of the Secure Hash Algorithm family. The four SHA algorithms are structured differently and are named SHA-0, SHA-1, SHA-2, and SHA-3. SHA1 is a one-way hash function and it computes a 160-bit message digest. SHA-1 often appears in security protocols for example, many HTTPS websites use RSA with SHA-1 to secure their connections. BitTorrent uses SHA-1 to verify downloads. Git and Mercurial use SHA-1 digests to identify commits.
SHA1("UiTM Jasin Melaka 2015. Fare Well Everyone!")
Hexadecimal: 0eb2acda4c34c9a13097a299f561c7b2d592e8bf
Even a small change in the message will, with overwhelming probability, result in a completely different hash due to the avalanche effect.
SHA1("UiTM Jasin Melaka 2015. FareWell Everyone!")
Hexadecimal: 543232d470af26e6b25644f820cbab88c214d1f1
SHA1("UiTM Jasin Melaka 2015. Fare Well Everyone!")
Hexadecimal: 0eb2acda4c34c9a13097a299f561c7b2d592e8bf
Even a small change in the message will, with overwhelming probability, result in a completely different hash due to the avalanche effect.
SHA1("UiTM Jasin Melaka 2015. FareWell Everyone!")
Hexadecimal: 543232d470af26e6b25644f820cbab88c214d1f1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import java.security.*; public class HashTextTest { public static void main(String[] args){ System.out.println(sha1("UiTM Jasin Melaka 2015. Fare Well Everyone!")); } public static String sha1(String str){ StringBuffer shasum = new StringBuffer(); try{ MessageDigest mDigest = MessageDigest.getInstance("SHA1"); byte[] result = mDigest.digest(str.getBytes()); for (int i = 0; i < result.length; i++) { shasum.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1)); } } catch(NoSuchAlgorithmException e){ e.printStackTrace(); } return shasum.toString(); } } |
Thursday, September 24, 2015
Matlab: Removing silence part in signal processing
I am just try and error in this matlab thing about a month ago tried to figure out a way to remove silence in signal. And at last i have found this solution on youtube.
[x,Fs] = audioread('Matlab\data\wav\example.wav'); no_silence_sig = silence_removal(Fs,x);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | function no_silence_sig = silence_removal(fs,get_audio) frame_len = 0.01*fs; % 0.01 per frame N = length(get_audio); num_frames = floor(N/frame_len); new_sig = zeros(N,1); count = 0; for k=1:num_frames frame = get_audio((k-1)*frame_len+1 : frame_len*k); max_val = max(frame); %only append signal at amplitude >0.02 if(max_val > 0.02) count = count+1; new_sig((count-1)*frame_len+1 : frame_len*count) = frame; end end % remove trailing zero in signal no_silence_sig=new_sig(1:find(new_sig, 1, 'last')); end |
Merge Sort
The merge sort is a recursive sort of order n*log(n). It is notable for having a worst case and average complexity of O(n*log(n)), and a best case complexity of O(n) (for pre-sorted input). The basic idea is to split the collection into smaller groups by halving it until the groups only have one element or no elements (which are both entirely sorted groups). Then merge the groups back together so that their elements are in order. This is how the algorithm gets its "divide and conquer" description.
Worst case performance : O(n log n)
Best case performance : O(n log n)
Average case performance : O(n log n)
Conceptually, a merge sort works as follows:
This is the pseudocode of merge sort
Worst case performance : O(n log n)
Best case performance : O(n log n)
Average case performance : O(n log n)
Conceptually, a merge sort works as follows:
- Divide the unsorted list into n sublists, each containing 1 element (a list of 1 element is considered sorted).
- Repeatedly merge sublists to produce new sorted sublists until there is only 1 sublist remaining. This will be the sorted list.
This is the pseudocode of merge sort
function mergesort(m)
var list left, right, result
if length(m) ≤ 1
return m
else
var middle = length(m) / 2
for each x in m up to middle - 1
add x to left
for each x in m at and after middle
add x to right
left = mergesort(left)
right = mergesort(right)
if last(left) ≤ first(right)
append right to left
return left
result = merge(left, right)
return result
function merge(left,right)
var list result
while length(left) > 0 and length(right) > 0
if first(left) ≤ first(right)
append first(left) to result
left = rest(left)
else
append first(right) to result
right = rest(right)
if length(left) > 0
append rest(left) to result
if length(right) > 0
append rest(right) to result
return result
Quick Sort
Quicksort is an efficient sorting algorithm, serving as a systematic method for placing the elements of an array in order. Quicksort is a comparison sort, meaning that it can sort items of any type for which a "less-than" relation is defined. On average, the algorithm takes O(n log n) comparisons to sort n items. In the worst case, it makes O(n2) comparisons, though this behavior is rare. Quicksort is at one end of the spectrum of divide-and-conquer algorithms, which does most of the work during the partitioning and the recursive calls.
Steps
Steps
- Choose any element of the array to be the pivot.
- Divide all other elements (except the pivot) into two partitions which is all elements less than the pivot must be in the first partition and all elements greater than the pivot must be in the second partition.
- Use recursion to sort both partitions.
- Join the first sorted partition, the pivot, and the second sorted partition.
What is the programming competition?
What is the programming competition?
The programming competition is just that, a competition during which teams compete by attempting to code correct solutions to as many of the problems that they can within 5 hours. The problems are not just 'undergrad assignment' questions, they are scenarios that will require you to develop a non-trivial algorithm that correctly simplifies the problem into a form that can be solved very quickly (solutions must generally be able to solve a multi-thousand solution in under 3 minutes).
Why should i join programming competition
Aside from ego, pride or otherwise acquired bragging rights, the is also a very good opportunity to develop your skills of problem solving under pressure which every person this side of the wilderness will need to have throughout their life style. Understanding how you came to a given solution and even understanding why that solution was wrong (or inelegant), can help you to develop your problem solving skills. By reading only textbook you will never improved yourself.
Student/people usually will think that "oh man, that sounds hard". Actually, it is and it isn't. The most common misconception is that you need to be a 'wizard' coder to do well. In fact, many successful teams bring with them printed notes of how to perform the more tedious coding tasks so that they can spend their time working on finding a good solution rather than wasting it trying to remember the correct algorithm for a depth-first search.
Team Strategy Tips
Hint
I am too not a expert in this, but I would recommend the following things according to my experiences :
The programming competition is just that, a competition during which teams compete by attempting to code correct solutions to as many of the problems that they can within 5 hours. The problems are not just 'undergrad assignment' questions, they are scenarios that will require you to develop a non-trivial algorithm that correctly simplifies the problem into a form that can be solved very quickly (solutions must generally be able to solve a multi-thousand solution in under 3 minutes).
Why should i join programming competition
Aside from ego, pride or otherwise acquired bragging rights, the is also a very good opportunity to develop your skills of problem solving under pressure which every person this side of the wilderness will need to have throughout their life style. Understanding how you came to a given solution and even understanding why that solution was wrong (or inelegant), can help you to develop your problem solving skills. By reading only textbook you will never improved yourself.
Student/people usually will think that "oh man, that sounds hard". Actually, it is and it isn't. The most common misconception is that you need to be a 'wizard' coder to do well. In fact, many successful teams bring with them printed notes of how to perform the more tedious coding tasks so that they can spend their time working on finding a good solution rather than wasting it trying to remember the correct algorithm for a depth-first search.
Team Strategy Tips
- If you are not sure about your solution, discuss it with your teammates. If stuck, explain problem to a teammate. Use good judgement if it is worth the interruption of him/her.
- If you are stuck on a problem, take a walk or go to the toilet. The best ideas come to mind here.
- Look at the scoreboard every now and then. If there is a problem that many other teams solved, it should be easy.
- Usually there are 10 question. Split every question with your teammate, read and choose the easiest one.
- Discus with your teammate who is the coder, who is thinker and who is the algorithmer.
- Don't spend to much time on one question. Try to solve other while your teammate think another solution.
- When you are done with a problem, separate it. Don't mess your table.
- Eat to release tension..that is i always do.
Hint
I am too not a expert in this, but I would recommend the following things according to my experiences :
- Choose a programming language you are going to use in all the competitions. I would say the best choice is Java because java have a lot of library that i can use and easy to remember rather than hard coder.
- Learn algorithm such as Sorting, Searching, Combination, Permutation, Graph, Palindrome, Bruce force, Dynamic Programming, etc..
- Mathematics algorithm also important such as Algebra, Summation, Cubic, Angle and etc But it is not necessary for me.
- For people using Java as their programming language, i use library such as StringBuilder, BigInteger, HashMap, Scanner, BufferedReader, Math, Arrays, HashMap, Vector, String, Character. Its really help me.
- Get some theoretical knowledge of algorithms. Book written by Steven Halim shows you how to solve problem in vary such way. It contains pretty much all the algorithms, math and data structures you need to know for programming competitions.
- Go to website called Hackerearth, Hackerrank, Codechef or else, they provide platform where you can practice to solve the problem provided.
Wednesday, September 23, 2015
Password hash with MD5
The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32 digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications, and is also commonly used to verify data integrity.
MD5 is very collision resistant. The algorithm was designed to generate unique hash values for each unique input. However, lately there have been rumblings in the security community about the weaknesses in MD5. Many government agencies will be required to move to a stronger algorithm in a few years.
Advantages of MD5
MD5 is very collision resistant. The algorithm was designed to generate unique hash values for each unique input. However, lately there have been rumblings in the security community about the weaknesses in MD5. Many government agencies will be required to move to a stronger algorithm in a few years.
Advantages of MD5
- Utilizes a fast computation algorithm
- Provides collision resistance
- Is in widespread use
- Provides a one-way hash
- Has known security flaws and vulnerabilities
- Is less secure than the SHA-1 algorithm
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import java.security.*; public class MD5 { public static void main(String[] args) { String passwordToHash = "HELLOWORLD"; StringBuilder sb = new StringBuilder(); try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(passwordToHash.getBytes()); byte[] bytes = md.digest(); for(int x=0; x< bytes.length ;x++){ sb.append(String.format("%02x", bytes[x])); } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } System.out.println(sb.toString()); } } |
Subscribe to:
Posts (Atom)





