ROT13 Algorithm Using Python

ROT13 (“rotate by 13 places”, sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the letter 13 letters after it in the alphabet. ROT13 is an example of the Caesar cipher, developed in ancient Rome.(Source Wiki). Here Is the new version I have written to apply ROT 13 for alphabets only, special characters are not touched they will remain as it is.

I have tried to implement this Algorithm Using Python. Here it goes..

# ROT13 Algorithm

def rot(text):
arr = list(text)
for i in range(len(arr)):
if (ord(arr[i]) > 64 and ord(arr[i]) <91) or (ord(arr[i])>96 and ord(arr[i])<123): #check for alphabets only
nextCharValue = (ord(arr[i]) + 13) #sum
asciValue = ord(arr[i]) #ascii value
# print “ascii “,asci, ” sum”, sum
if asciValue > 64 and asciValue < 91:
if nextCharValue > 90:
newValue = ord(arr[i]) – 13
newValue = ord(arr[i]) + 13
elif asciValue> 96 and asciValue < 123:
if nextCharvalue > 122:
newValue = ord(arr[i]) – 13
newValue = ord(arr[i]) + 13

arr[i] = chr(newValue)

return ”.join(arr)


str = rot(‘How can you tell an extrovert from an introvert at NSA? ‘)
print “ROT13:-“, str
print “Back to original:- “, rot(str)

Please share your feedback, I am open for any suggestions.(you can also have a look on the code where I have tested this


R Vashi


Pattern search in String using Python

For fun I just thought about writing an algorithm on using pattern search in any given string using python, Lets assume you have a string with a value of “SSDDFFEERRTTYYSS” and a character array [‘D’,’D’], Now use the values of character array as a pattern and search for the maximum character occurrence of match in the string value. in plain words, we have a ..


pattern : [‘D’,’D’] i.e DD

Expected output is :3 (as DD pattern appears thrice [XXDDXXXXXDDDXXX).

Also assume the Char array can be dynamic, I mean could be of any limit of characters.

#@Author :rvashisht

char =[‘D’,’D’]
count = 0

i =0
j = 0
pattern = ”
charLength = len(char) # get the length of char array
for i in range(len(char)):
pattern += char[i]

for j in range(len(string)-1):
#extract the chars from string, it should match char pattern length
chars = string[ j : j+charLength] #search in string with pattern
if pattern == chars : #check if pattern match
print chars, “=”, pattern
count = count +1 # increase the counter

print “Total occurrence of pattern found”, count

Well this is just a try.. Please review and comment..




Bubble Sort using Python

I have recently started using Python basically Jython to use with Java applications. The love for python is growing, I kind of started liking code in Python. Though I am still looking for some more practical reasons where I can see the effective mixing of Java and Python. So I started with  very basic program of doing bubble sort on a collection. Here it goes.

import time;

class BubbleSort() :

def __init__(self):

def doSearch(self):
list = [33,23, 13, 43, 63,53,73,83,93, 3]
found = 1 # assume there is at least one item to sort
while (found == 1): #set infinite loop
pos = 0; # start with initial pos
for i in range(len(list)-1):
next = list[i+1] #get the next element
if list[i] > next :
list[i+1] = list[i] #do a swap
list[i] = next
#print list
pos = i;

          if pos == 0:
found = 0 # all sorted, exit loop

print list

def getTime(self):
localtime = time.asctime( time.localtime(time.time()))
print localtime;

if __name__ == “__main__”:
obj = BubbleSort()

Keep watching for few more useful posts on Python/Jython.

R Vashi

Code Bubble IDE


I have worked on many different IDE’s (Integrated Development Environment) like Eclipse, Intellij, Jboss Studio, JCreator and few others, but working on code bubbles programming environment is unbelievable. Its pretty awesome…

Here is the video link on You Tube. Check this out.. if you really love to code on Java. Really hats off to the Code Bubble team.



What’s new in IBM RAD V8

Rational Application Developer for WebSphere Version 8.0 provides a simpler and streamlined way to develop Java EE 6 software, Web 2.0 rich internet applications, and Service Oriented Architecture (SOA) solutions. This release provides an integrated environment for agile developers to quickly build, test and analyze their work on the latest versions of WebSphere Application Server. Read below link for more details.’s+New

R Vashi

Using Websphere MQ with JBoss AS 5

IBM WebSphere MQ is a family of network software products launched by IBM in March 1992. It was previously known as MQSeries, a trademark that IBM rebranded in 2002 to join the suite of WebSphere products. WebSphere MQ, which is often referred to simply as “MQ” by users, is IBM’s Message Oriented Middleware offering(JMS).

Lets see how we can configure MQ with Jboss as a pert of JMS.

Step 1: Install JBoss 5
To install JBoss AS 5, You can download it from this link

Step 2: Install Webpshere MQ 7
To install visit IBM website and download a free copy of trial.

Step3: Install wmq.jmsra.rar
The copy of wmq.jmsra.rar could be found in Inside WebSphere mq install directory e.g  wmq/java/lib/jca, Also the same can be found  if you have WAS installed. Once you got this copy put it in JBOSS_HOME/server/default/deploy

Step 4: Create wmq.jmsra-ds.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<xa-transaction />
<config-property name=”channel” type=”java.lang.String”>SYSTEM.DEF.SVRCONN</config-property>
<config-property name=”hostName” type=”java.lang.String”></config-property>
<config-property name=”port” type=”java.lang.String”>1417</config-property>
<config-property name=”queueManager” type=”java.lang.String”>JBOSS_QM</config-property>
<config-property name=”transportType” type=”java.lang.String”>CLIENT</config-property>
<mbean code=”org.jboss.resource.deployment.AdminObject” name=”jca.wmq:name=ivtqueue”>
<!– Bind this AdminObject with the JNDI name IVTQueue –>
<attribute name=”JNDIName”>IVTQueue</attribute>
<depends optional-attribute-name=”RARName”>jboss.jca:service=RARDeployment,name=’wmq.jmsra.rar'</depends>
<attribute name=”Type”>javax.jms.Queue</attribute>
<attribute name=”Properties”>

Step 5:  Create a EJB 3.0 project in JBoss Studio or in Eclipse IDE.

Step 6: Write a Message Driven Bean



import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.jms.BytesMessage;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.jboss.ejb3.annotation.ResourceAdapter;

* Message-Driven Bean implementation class for: MQJbossExample

@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = “destinationType”,
propertyValue = “javax.jms.Queue”),

@ActivationConfigProperty(propertyName = “messagingType”,
propertyValue = “javax.jms.MessageListener”),

@ActivationConfigProperty(propertyName = “destination”, propertyValue = “JBOSS_Q”),

@ActivationConfigProperty(propertyName = “queueManager”, propertyValue = “JBOSS_QM”),
@ActivationConfigProperty(propertyName = “hostName”, propertyValue = “”),
@ActivationConfigProperty(propertyName = “port”, propertyValue = “1417”),
@ActivationConfigProperty(propertyName = “channel”, propertyValue = “SYSTEM.DEF.SVRCONN”),

@ActivationConfigProperty(propertyName = “transportType”,propertyValue = “CLIENT”), },

messageListenerInterface = MessageListener.class)


public class MQJbossExample implements MessageListener, MessageDrivenBean {

private int maxMessageLength = 50820;

private BytesMessage byteMessage = null;

private static final long serialVersionUID = 1L;

String recievedMessageFromWSMq = “”;

* Default constructor.
public MQJbossExample() {
// TODO Auto-generated constructor stub

* @see MessageDrivenBean#ejbRemove()
public void ejbRemove() {
// TODO Auto-generated method stub

* @see MessageDrivenBean#setMessageDrivenContext(MessageDrivenContext)
public void setMessageDrivenContext(MessageDrivenContext arg0) {
// TODO Auto-generated method stub

* @see MessageListener#onMessage(Message)
public void onMessage(Message message) {
// TODO Auto-generated method stub
try {

if (message != null) {

if (message instanceof TextMessage) {

recievedMessageFromWSMq = ((TextMessage) message).getText();
System.out.println(” recievedMessageFromWSMq ”
+ recievedMessageFromWSMq);

} else if (message instanceof BytesMessage) {

byteMessage = (BytesMessage) message;

byte[] buffer = new byte[maxMessageLength];

int byteRead;

ByteArrayOutputStream bOut = new ByteArrayOutputStream();

while ((byteRead = byteMessage.readBytes(buffer)) != -1) {

bOut.write(buffer, 0, byteRead);


try {


recievedMessageFromWSMq = new String(bOut.toByteArray());
System.out.println(” recievedMessageFromWSMq ”
+ recievedMessageFromWSMq);


} catch (Exception e) {





} catch (JMSException e1) {




Step 7:  Now Build the project.Start the server, If all the configuration are correct then you will see binding information of the JNDI name in the server logs, This is the first indication that Link between MQ and JBoss has successfully created.

21:13:29,812 INFO [ConnectionFactoryBindingService] Bound ConnectionManager ‘jboss.jca:service=ConnectionFactoryBinding,name=JmsXA’ to JNDI name ‘java:JmsXA’
21:13:29,984 INFO [AdminObject] Bound admin object ‘’ at ‘IVTQueue’

Step 8:  Now deploy the application on Jboss.

21:15:42,515 INFO  [EJBContainer] STARTED EJB: ejbName: MQJbossExample

Step 9: Now Open Websphere MQ Explorer and put a message on the Queue.

Step 10: Once you put a dummy message on the Queue, See in the server logs to observe the message recived by our Message Driven bean.

See how simple it is to integrate Jboss with MQ. Hope this helps 🙂

R Vashi

Configuring Wired LAN(internet) on Ubuntu


In this post I will explain the ways we can configure Wired LAN connection on Ubuntu. While configuring any network resource we always need the IP Address to connect to the Domain/Network System. And this IP Address we configure either manually or using DHCP option(DHCP – the Dynamic Host Configuration Protocol – allows network devices to automatically obtain a valid IP address from a server.). There are many networking utilities we can use to configure the network, Now let see Network Interface configuration Using Command-Line.

Step 1: Go to Terminal and Type the below command.

gksudo gedit /etc/network/interfaces (if you have GUI)
sudo vi /etc/network/interfaces (use vi if no GUI installed)

Step 2:
-> Change to set if using DHCP

auto eth0
iface eth0 inet manually
auto eth0
iface eth0 inet dhcp

-> Change to set if using Static IP

auto eth0
iface eth0 inet static

Step 3: Save the file.

Step 4: After you save the file, Its time to restart networking services.

sudo /etc/init.d/networking restart

Now go to Administration -> System Monitor and click on the Resources Tab and observe the Network History to see the Network connection graph.

Yepeee.. you are now connected 🙂

R Vashi