I've looked at a few alternatives for encryption with Python, and
didn't come up anything very speedy.
I've written an encryption algorithm in pure Python that can process
22 megs of data a second. I know it's not secure, but it should be
enough to ward off casual hacking. Does someone know of something
speedier?
--Kamilche 22 3236
Kamilche wrote: I've looked at a few alternatives for encryption with Python, and didn't come up anything very speedy.
I've written an encryption algorithm in pure Python that can process 22 megs of data a second. I know it's not secure, but it should be enough to ward off casual hacking. Does someone know of something speedier?
If you're only concerned with warding off casual hacking, and speed is
your maximal concern, why not just XOR each byte with 0xFF or something
equally brainless?
--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
\__/ Freedom is never voluntarily given by the oppressor.
-- Dr. Martin Luther King, Jr. kl*******@home. com (Kamilche) writes: I've written an encryption algorithm in pure Python that can process 22 megs of data a second. I know it's not secure, but it should be enough to ward off casual hacking. Does someone know of something speedier?
Yes, you can just copy the input to the output. That's quite fast,
and it's at least as insecure as your method.
Kamilche wrote: I've looked at a few alternatives for encryption with Python, and didn't come up anything very speedy.
I've written an encryption algorithm in pure Python that can process 22 megs of data a second. I know it's not secure, but it should be enough to ward off casual hacking. Does someone know of something speedier?
In addition to Erik and Paul's comments: if you don't specify
what machine you ran your benchmark on, the number "22MB/s" is
completely meaningless...
Besides, what you say is not possible. On my machine,
which is about a P4 2500MHz, scanning an array.array('c' ) with
22MB of data in it, doing nothing but reading each byte and
ignoring it, takes about 8 seconds. So does converting the
array to a list, which is pretty much all C code. Strings
are immutable, so you can't be working with one of them...
Doing anything meaningful with real data, no matter how trivial
the algorithm, would definitely take longer.
-Peter
Peter Hansen <pe***@engcorp. com> writes: Besides, what you say is not possible. On my machine, which is about a P4 2500MHz, scanning an array.array('c' ) with 22MB of data in it, doing nothing but reading each byte and ignoring it, takes about 8 seconds. So does converting the array to a list, which is pretty much all C code. Strings are immutable, so you can't be working with one of them...
Well, you could do 32-bit operations which are maybe 4x faster.
You could maybe get even more speedup using built-in C functions.
For example, you could do rot13 encryption with the string.translat e
method which should be quite fast. FWIW, http://www.nightsong.com/phr/crypto/p3.py
should be quite secure, and should run at least 1 mbyte/sec on your
p4/2500, maybe quite a bit more.
Paul Rubin wrote: Peter Hansen <pe***@engcorp. com> writes:
Besides, what you say is not possible. On my machine, which is about a P4 2500MHz, scanning an array.array('c' ) with 22MB of data in it, doing nothing but reading each byte and ignoring it, takes about 8 seconds. So does converting the array to a list, which is pretty much all C code. Strings are immutable, so you can't be working with one of them...
Well, you could do 32-bit operations which are maybe 4x faster. You could maybe get even more speedup using built-in C functions. For example, you could do rot13 encryption with the string.translat e method which should be quite fast.
Both are good ideas, but I made an assumption that I was starting
with a simple 22MB string, and the cost of converting that to 32-bit
(presumably using array.array still?) would have to be taken into
account, for fairness. I also assume Kamilche wasn't talking
about using the builtin rot13, since he claimed to have written
this himself...
-Peter
Take a look at pyCrypto. My understanding is that
it provides python wrapper around C crypto functions.
Can't get much faster than that. http://www.amk.ca/python/code/crypto.html
HTH,
Larry Bates
"Kamilche" <kl*******@home .com> wrote in message
news:88******** *************** ***@posting.goo gle.com... I've looked at a few alternatives for encryption with Python, and didn't come up anything very speedy.
I've written an encryption algorithm in pure Python that can process 22 megs of data a second. I know it's not secure, but it should be enough to ward off casual hacking. Does someone know of something speedier?
--Kamilche
Peter Hansen <pe***@engcorp. com> writes: Both are good ideas, but I made an assumption that I was starting with a simple 22MB string, and the cost of converting that to 32-bit (presumably using array.array still?) would have to be taken into account, for fairness. I also assume Kamilche wasn't talking about using the builtin rot13, since he claimed to have written this himself...
There's no special conversion needed, just use array.array('L' , whatever)
instead of array.array('B' , whatever), if I remember right.
Paul Rubin wrote: Peter Hansen <pe***@engcorp. com> writes:the cost of converting that to 32-bit (presumably using array.array still?) ....
There's no special conversion needed, just use array.array('L' , whatever) instead of array.array('B' , whatever), if I remember right.
Cool! I didn't realize you could initialize effectively any
array object from a string as well as a list. Never too late
to read the docs... :-)
-Peter
Peter Hansen <pe***@engcorp. com> wrote in message news:<Td******* *************@p owergate.ca>... Besides, what you say is not possible. On my machine, which is about a P4 2500MHz, scanning an array.array('c' ) with 22MB of data in it, doing nothing but reading each byte and ignoring it, takes about 8 seconds. So does converting the array to a list, which is pretty much all C code. Strings are immutable, so you can't be working with one of them...
Doing anything meaningful with real data, no matter how trivial the algorithm, would definitely take longer.
But I DON'T manipulate the data byte by byte, only the encryption
tables.
Ah, the power of algorithms! ;-)
Take a look at this:
def encrypt(s, offset = 0, _tables = []):
' Encrypt or decrypt a string'
cnt = len(_tables)
if cnt == 0:
# Initialize static variable _tables
# Increase 'cnt' to prevent recurring patterns.
import random
cnt = 10
random.seed(257 )
for i in range(cnt):
marked, table, max = [], [], 256
for j in range(max):
table.append(ch r(j))
marked.append(F alse)
marked[0] = True
marked[255] = True
for j in range(max):
if not marked[j]:
while 1:
c = random.randint( 0, 255)
if marked[c] == False:
table[j], table[c] = table[c], table[j]
marked[c] = True
marked[j] = True
break
_tables.append( ''.join(table))
# Tables initialized - encrypt the data.
return s.translate(_ta bles[offset % cnt])
s = "This is a standard length string to encrypt."
print "\nYou need to specify an offset to avoid patterns."
print "The string is:", s
print "\nEncrypte d with offsets, you get:"
for i in range(5):
print "\t", encrypt(s, i)
print "\nEncrypte d without offsets, you get:"
for i in range(5):
print "\t", encrypt(s)
Most XOR algorithms could benefit from using this technique. There's
never a need to XOR a byte more than once, while building the table.
From then on, it's a simple substitution problem, which the
'translate' function accomplishes quite nicely. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Anthony Baxter |
last post by:
On behalf of the Python development team and the Python community, I'm
happy to announce the release of Python 2.3.1 (final).
Python 2.3.1 is a pure bug fix release of Python 2.3, released in late
July. A number of obscure crash-causing bugs have been fixed, various
memory leaks have been squished, but no new features have been added to
the language or to the library.
For more information on Python 2.3.1, including download links for...
|
by: John Burton |
last post by:
One of the reasons I like python so much is that the standard
installation comes with a whole lot of libraries to do lots of useful
things but there seem to be a few things missing from the standard
library which would be useful in many projects:
Encryption - AES and 3DES. Possibly RSA and Certificate processing.
DNS - Something better than gethostbyaddr for looking up other record types.
Database - Something suitable for small projects...
|
by: Daniel Orner |
last post by:
Hello,
I'm working on a project that consists of a Java application on the
desktop, and a server with Python CGI code. I'm trying to find an
encryption algorithm, which would let me send encrypted information to
the server, to work identically in both Python and Java. (I.e. which
would let me encrypt data in Java, send it to the Python server, and
decrypt it there.) For various reasons, I don't want to use the built-in
Java encryption...
|
by: drs |
last post by:
Hi, I need to send secure data over an insecure network. To that end, I am
needing to encrypt serialized data and then decrypt it. Is there a builtin
way to do this in Python? MD5, SHA, etc encrypt, but I am not seeing a way
to get back my data. Encryption is totally new to me, so any pointers of
what to read up on would be appreciated.
As a side note, I understand that I could use https, but this would involve
changing things that I...
|
by: Blake T. Garretson |
last post by:
I want to save some sensitive data (passwords, PIN numbers, etc.) to
disk in a secure manner in one of my programs. What is the
easiest/best way to accomplish strong file encryption in Python? Any
modern block cipher will do: AES, Blowfish, etc. I'm not looking for
public key stuff; I just want to provide a pass-phrase.
I found a few modules out there, but they seem to be all but abandoned.
Most seem to have died several years ago. ...
| |
by: dirvine |
last post by:
HI hope you can help (know you can).
I am looking for a very strong AIS or better symetrical encryption in
python. Any suggestions ideas welcome. I have spent a lot of time
looking everywhere at pycrypto and many others but is a wee bit of a
minefield out there. Anyone have any experience of a true encryption
(not xor or anything weak). I am looking for something strong enough to
encrypt your credit card info and publish file on website...
|
by: Michael Sperlle |
last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems
to need changes to the kernel before it can be installed, and I have no
intention of going through whatever hell that would cause.
If I could create a large file that could be encrypted, and maybe add
files to it by appending them and putting in some kind of delimiter
between files, maybe a homemade version of truecrypt could be constructed.
Any idea what it...
|
by: Robert Blass |
last post by:
I am looking to get my feet wet with encryption. When I say encryption
program I am talking about something to get me off to a quick start.
Something very simple, far less than the 40+ bit encryption code.
What I need is an easy to understand language choice. I've used BASIC
a long time ago but is there another language that is better and more
supported?
There seems to be hundreds of languages so it's hard for me to just
pick one.
|
by: Netwatcher |
last post by:
well, i started messing around with dictionaries, yet, most of the pages i found about them always talk about getting only one word out of it and turning it vice versa, i've been playing with that code for a few hours:
#dics
Encryption={',':'hy{;',' ':'h4x0r2','':'zomg','?':'bko','a':'ika','b':'d0v','c':'ino', 'd':'maw', 'e':'aon', 'f':'que', 'g':'kip', 'h':'an', 'n':'ko
print lol
except KeyError:
print 'These...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |