<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sp2hari@weblog... &#187; Shell-Scripting</title>
	<atom:link href="http://sp2hari.com/tag/shell-scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://sp2hari.com</link>
	<description>I see, learn and rediscover... everyday!</description>
	<lastBuildDate>Thu, 24 Nov 2011 22:06:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Advanced Bash Scripting &#8211; Part 2</title>
		<link>http://sp2hari.com/2010/07/27/advanced-bash-scripting-part2/</link>
		<comments>http://sp2hari.com/2010/07/27/advanced-bash-scripting-part2/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 00:11:31 +0000</pubDate>
		<dc:creator>sp2hari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Shell-Scripting]]></category>

		<guid isPermaLink="false">http://sp2hari.com/?p=572</guid>
		<description><![CDATA[The problem statement is as follows : The Playfair Cipher encrypts text by substitution of digrams (2-letter groupings). It is traditional to use a 5 x 5 letter scrambled-alphabet key square for the encryption and decryption. Each letter of the &#8230; <a href="http://sp2hari.com/2010/07/27/advanced-bash-scripting-part2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://sp2hari.com/wp-content/uploads/2010/03/application-x-shellscript.png"><img src="http://sp2hari.com/wp-content/uploads/2010/03/application-x-shellscript.png" alt="Shell Script" title="application-x-shellscript" width="128" height="128" class="alignleft size-full wp-image-446" /></a><strong>The problem statement is as follows : </strong></p>
<p>The Playfair Cipher encrypts text by substitution of digrams (2-letter groupings). It is traditional to use a 5 x 5 letter scrambled-alphabet key square for the encryption and decryption.</p>
<p>Each letter of the alphabet appears once, except &#8220;I&#8221; also represents &#8220;J&#8221;. The arbitrarily chosen key word, &#8220;CODES&#8221; comes first, then all the rest of the alphabet, in order from left to right, skipping letters already used.</p>
<p>To encrypt, separate the plaintext message into digrams (2-letter groups). If a group has two identical letters, delete the second, and form a new group. If there is a single letter left over at the end, insert a &#8220;null&#8221; character, typically an &#8220;X.&#8221;</p>
<p>To read more about the question, check <a href="http://tldp.org/LDP/abs/html/writingscripts.html">http://tldp.org/LDP/abs/html/writingscripts.html</a></p>
<p>The solution for this question is pretty long (over 100 lines in shell script). You can check the final solution at <a href="http://sp2hari.com/bash/playfair-cipher.html">http://sp2hari.com/bash/playfair-cipher.html</a></p>
<p>Explanation of function/code used in the solution.</p>
<p><strong>locateInKeySquare</strong>: Searches for the character passed as the parameter in the keySquare and returns the position of the character.<br />
<strong>addToKeySquare</strong>: Adds a character c passed as the parameter to the keySquare. This checks if the character is already present, if it is J and changes it to uppercase (if needed)<br />
<strong>printKeySquare</strong>: Prints the keySquare from 1D to 2D format. </p>
<p>The rest of the code adds the keyWord to keySquare. The the remaining words are added to the keySquare. After that, we extract the dialects from the plaintext and based on the 3 rules, we encrypt the text. </p>
<p>Hope this is helpful.. </p>
]]></content:encoded>
			<wfw:commentRss>http://sp2hari.com/2010/07/27/advanced-bash-scripting-part2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Advanced Bash Scripting &#8211; Part 1</title>
		<link>http://sp2hari.com/2010/03/31/advanced-bash-scripting-part-1/</link>
		<comments>http://sp2hari.com/2010/03/31/advanced-bash-scripting-part-1/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 11:32:27 +0000</pubDate>
		<dc:creator>sp2hari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Shell-Scripting]]></category>

		<guid isPermaLink="false">http://sp2hari.com/?p=445</guid>
		<description><![CDATA[Hello everyone, I&#8217;m planning to solve the problems in the Advanced Bash-Scripting Guide, say like one problem per week. Why am I doing this? 1. The problems there are very interesting. 2. Working in windows all the time, I feel &#8230; <a href="http://sp2hari.com/2010/03/31/advanced-bash-scripting-part-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://sp2hari.com/wp-content/uploads/2010/03/application-x-shellscript.png"><img src="http://sp2hari.com/wp-content/uploads/2010/03/application-x-shellscript.png" alt="Shell Script" title="application-x-shellscript" width="108" height="108" class="alignleft size-full wp-image-446" align="left"/></a> </p>
<p>Hello everyone, I&#8217;m planning to solve the problems in the <a href="http://tldp.org/LDP/abs/html/writingscripts.html">Advanced Bash-Scripting Guide</a>, say like one problem per week. Why am I doing this?</p>
<p>1. The problems there are very interesting.<br />
2. Working in windows all the time, I feel I&#8217;m losing my shell scripting abilities. This will keep me updated. </p>
<p>The problem we are going to solve this week is &#8220;Testing Passwords&#8221;. The problem statement is as follows.</p>
<p>Write a script to check and validate passwords. The object is to flag &#8220;weak&#8221; or easily guessed password candidates.<br />
A trial password will be input to the script as a command-line parameter. To be considered acceptable, a password must meet the following minimum qualifications:</p>
<p>1. Minimum length of 8 characters<br />
2. Must contain at least one numeric character<br />
3. Must contain at least one of the following non-alphabetic characters: @, #, $, %, &#038;, *, +, -, =</p>
<p>Optional:<br />
Do a dictionary check on every sequence of at least four consecutive alphabetic characters in the password under test. This will eliminate passwords containing embedded &#8220;words&#8221; found in a standard dictionary.<br />
Enable the script to check all the passwords on your system. These probably do not reside in /etc/passwd.</p>
<p>The command I&#8217;m planning to use for this is grep, with a few for loop constructs and string operations. </p>
<p>Let&#8217;s check the constraints one by one. </p>
<p><code>#Minimum length of 8 characters<br />
if [ ${#password} -lt 8 ]<br />
then<br />
&nbsp;&nbsp;echo "$password: $weakString"<br />
&nbsp;&nbsp;return<br />
fi</code></p>
<p><code>#Must contain at least one numeric character<br />
if [ `echo $password | grep -c -E "[0-9]+"` -eq 0 ]<br />
then<br />
&nbsp;&nbsp;echo "$password: $weakString"<br />
&nbsp;&nbsp;return<br />
fi</code></p>
<p><code>#Must contain at least one of the following non-alphabetic characters: @, #, $, %, &#038;, *, +, -, =<br />
if [ `echo $password | grep -c -E "[@#$%&#038;*=+-]+"` -eq 0 ]<br />
then<br />
&nbsp;&nbsp;echo "$password: $weakString"<br />
&nbsp;&nbsp;return<br />
fi</code></p>
<p><code>#Do a dictionary check on every sequence of at least four consecutive alphabetic characters in the password under test. This will eliminate passwords containing embedded "words" found in a standard dictionary.<br />
for((i=4;i<=${#password};i++))<br />
do<br />
&nbsp;&nbsp;for((j=0;j<=${#password}-$i;j++))<br />
&nbsp;&nbsp;do<br />
&nbsp;&nbsp;&nbsp;&nbsp;if [ `grep -c -E "^${password:$j:$i}$" dict.txt` -gt 0 ]<br />
&nbsp;&nbsp;&nbsp;&nbsp;then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo "$password: $weakString"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return<br />
&nbsp;&nbsp;&nbsp;&nbsp;fi<br />
&nbsp;&nbsp;done<br />
done</code></p>
<p>That's about it, we have checked all the constraints. Now, we will combine all the checks in one function and then we will pass all the  command line parameters to this function one by one. </p>
<p>You can take a look at the <a href="http://sp2hari.com/bash/testing-passwords.html">final script here</a>. </p>
<p>Can you make it any better or reduce the code size? Feel free to add it in the comments section.</p>
]]></content:encoded>
			<wfw:commentRss>http://sp2hari.com/2010/03/31/advanced-bash-scripting-part-1/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

