473,804 Members | 3,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XOR Binascii Hex Strings using the PyCrypto module


I snipped this bit of code out of Andrew Kuchling 'pyCrypto' test
fixture. Having a need to XOR Binascii Hex strings in my current
project, I found it very helpful to cut down on a bit of code
clutter.

So if you have a need for a Crypto module, this one seems to work off
the self without much effort and it comes /w a nice XOR function too
boot. :-)

PyCrypto can be found at: http://www.amk.ca/python/code/crypto

import binascii
from Crypto.Cipher import XOR

def die(string):
import sys
print '***ERROR: ', string
# sys.exit(0) # Will default to continuing onward...

testdata_xor = [('fffffffffffff fff',
'a5a5a5a5a5a5a5 a5','5a5a5a5a5a 5a5a5a')]

for entry in testdata_xor:
key,plain,ciphe r=entry
key=binascii.a2 b_hex(key)
plain=binascii. a2b_hex(plain)
cipher=binascii .a2b_hex(cipher )
obj=XOR.new(key )
ciphertext=obj. encrypt(plain)
print binascii.b2a_he x(ciphertext)

if (ciphertext!=ci pher):
die('XOR failed on entry '+`entry`)

Feb 16 '07 #1
0 2311

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
9887
by: Larry Bates | last post by:
I'm trying to get the results of binascii.crc32 to match the results of another utility that produces 32 bit unsigned CRCs. binascii.crc32 returns results in the range of -2**31-1 and 2**21-1. Has anyone ever worked out any "bit twiddling" code to get a proper unsigned 32 bit result from binascii.crc32? Output snip from test on three files: binascii.crc32=-1412119273, oldcrc32= 2221277246
1
2276
by: Jeremy | last post by:
I'm working on a project to create a keyfinder program that finds the Windows CD Key in the registry and decodes it. I prototyped it in Python and it worked great but for several reasons I've decided to rewrite it in C++. I use the module binascii extensively in the Python version but I can't find an equivalent module in C++. I'm not a professional developer so maybe I'm overlooking something simple. In particular I'm trying to find...
11
3038
by: dirvine | last post by:
Does anyone know if pycrypto is active at all. I have been browsing groups etc. for some info and have found entries from 2003 (latest) regarding some bits I was looking for in particular reference to symmetrical encoding (AES) and auto padding and supply or not of iv to set up method i.e from Crypto.Cipher import AES from Crypto.Hash import SHA256 import random import zlib
2
1868
by: Ed Swarthout | last post by:
Why is there no binascii.a2b_binary(bitstr) which returns the binary data represented by the bit string? Like: >>> binascii.a2b_binary('0011001100110101') '35' perl has pack("B*", "0011001100110101"); What is the python way to do this?
2
2503
by: Mike Meng | last post by:
Hi all, I'm learning Twisted and downloaded pyOpenSSL and pycrypto win32 installer on http://twisted.sourceforge.net/contrib/ . But I find the lastest version are for Python 2.3. I try to rebuild pyOpenSSL from source, but get lots of compile errors. Are these two packages obsolated? Where can I find updated version? Thank you in advance.
2
3650
by: Ning | last post by:
I'm trying to write an IM client which sends encrypted messages to the server. I tried to use pycrypto library, but when I came to 3DES cypher I was confused about the keysize to use. In the standard it said that it should be either 112 bits or 168 bits, whereas it's 16 bytes or 24 bytes in pycrypto. If I use 16 bytes key to encrypt and send this key to the server which is expecting a 112 bits key, there'll be a problem. How I should...
3
4317
by: mirandacascade | last post by:
Operating system: Win XP Vsn of Python: 2.4 Situation is this: Required to calcluate a message digest. The process for calcluating the digest must use an SHA-256 algorithm. Questions: 1) Is it correct that the sha module comes with python 2.4? 2) Is it correct that the sha module that ships with python 2.4 does NOT have the SHA-256 capability as part of the module?
5
12520
by: mirandacascade | last post by:
Attempting to determine whether the PyCrypto package has the capability to perform AES256 encryption. I received the following C# snippet: CryptoProvider provider = new CryptoProvider(); Encrypted_Type password = new Encrypted_Type(); password.EncryptedData = new EncryptedDataType(); password.EncryptedData.EncryptionMethod = new EncryptionMethodType(); password.EncryptedData.EncryptionMethod.Algorithm = "AES256-cbc"; and I was told...
6
5222
by: Vishal | last post by:
Hi, I have a file with a long list of hex characters, and I want to get a file with corresponding binary characters here's what I did: .... x = line.rstrip('\n') .... y = binascii.unhexlify(x) .... df.write(y)
0
9706
marktang
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...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10332
jinu1996
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...
0
10077
tracyyun
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...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
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();...
0
5522
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...
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.