Simple encryption in python


 
Thread Tools Search this Thread
Top Forums Programming Simple encryption in python
# 1  
Old 03-21-2012
Simple encryption in python

Hi,
i have the below script:
Code:
###############################SimpleEncryption################################
#Simple encryption implemented in python
#Author:pandeeswaran
###############################################################################

def Encrypt(input):
    res=''
    for i in input:
        k = len(input) + 1
        j=1
        while j < k:
          print("j is ",j)
          val = ord(i) + j
          res = res + ' ' + str(val)
          j = j + 1
          break
    return res

input=str(input("Enter the input string:\n"))
result=Encrypt(input)
print("The encrypted value is\n",result)

While running:
Code:
Enter the input string:
well
j is  1
j is  1
j is  1
j is  1
The encrypted value is
  120 102 109 109

But the output i expect is :
Code:
j is  1
j is  2
j is  3
j is  4
The encrypted value is
  120 103 111 112

Please help me in this.
thanks
# 2  
Old 03-21-2012
The 'break' at the bottom of the loop breaks the loop immediately, preventing j from counting higher.
# 3  
Old 03-21-2012
Bit if I remove the break also I am not getting the intended result
# 4  
Old 03-21-2012
What does it do, then?
# 5  
Old 03-21-2012
if i remove the break in the script, i am getting:
Code:
Enter the input string:
well
j is  1
j is  2
j is  3
j is  4
j is  1
j is  2
j is  3
j is  4
j is  1
j is  2
j is  3
j is  4
j is  1
j is  2
j is  3
j is  4
The encrypted value is
  120 121 122 123 102 103 104 105 109 110 111 112 109 110 111 112
>>>

But the output i need is :
Code:
120 103 111 112

# 6  
Old 03-21-2012
What algorithm are you trying to do?
# 7  
Old 03-21-2012
in my example: input text is "well".
So, the result should be :
Code:
(ascii value for w)+1 (ascii value for e)+2 (ascii value for l)+3  (ascii value for l)+4

Code:
 120 103 111 112

This is what i am trying.
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple Python Code Question

I have the following code: #!/usr/bin/env python mylist = def printWithoutNewlines(): for objects in mylist: #print(objects) objects = objects.replace('hello', "hi") print objects When executed, it gives the following output: ## ./loop.py hi... (3 Replies)
Discussion started by: SkySmart
3 Replies

2. OS X (Apple)

Python script to do simple audio capture...

This site is the first to get this snippet. It will capture an audio recording of any time length within the limits of OSX's QuickTime Player's capablility... A shell script derivative of this will be used as a further capture for CygWin's AudioScope.sh. Thoroughly read ALL the comments in... (0 Replies)
Discussion started by: wisecracker
0 Replies

3. Cybersecurity

File encryption tools with MAC address as an encryption key

Hi all, I'm looking for secure file encryption tools that use MAC address as encryption key. FYI, I'm using Red Hat Enterprise Linux OS. For example: when A wants to send file to B A will encrypt the file with B's computer MAC/IP address as an encryption key This file can only be decrypted... (2 Replies)
Discussion started by: sergionicosta
2 Replies

4. Homework & Coursework Questions

Help with Simple Perl/Python Script

I have the following problem, which I need done in Perl/ or Python using Unix/linux filters... 1. You have a very large file, named 'ColCheckMe', tab-delmited, that you are asked to process. You are told that each line in 'ColCheckMe' has 7 columns, and that the values... (1 Reply)
Discussion started by: Swapnilsagarwal
1 Replies

5. Shell Programming and Scripting

Help with Simple Perl/Python Script

I have the following problem, which I need done in Perl/ or Python using Unix/linux filters... 1. You have a very large file, named 'ColCheckMe', tab-delmited, that you are asked to process. You are told that each line in 'ColCheckMe' has 7 columns, and that the values in the... (1 Reply)
Discussion started by: Swapnilsagarwal
1 Replies

6. Red Hat

Writing simple python setup commands

Building software in most languages is a pain. Remember ant build.xml, maven2 pom files, and multi-level makefiles? Python has a simple solution for building modules, applications, and extensions called distutils. Disutils comes as part of the Python distribution so there are no other packages... (0 Replies)
Discussion started by: Linux Bot
0 Replies
Login or Register to Ask a Question