error in Crypto.Cipher.IDEA module in python - python

Hello there,
i am writing a code for auto discovery of IP within the network and then
data transfer using the socket programming in python. I have read the RSA
and want to implement in the code. i go through to the link where i got
the code implementation and the whole code for server and client.
Here is the link where the code is:
<https://riptutorial.com/python/example/27170/client-side-implementation>
<https://riptutorial.com/python/example/27169/server-side-implementation>
There are two links and the setup for PyCrypto is.
*PyCrypto (Download Link: https://pypi.python.org/pypi/pycrypto )
*PyCryptoPlus (Download Link: https://github.com/doegox/python-cryptoplus )
i tried it on raspberry pi and install all the essential modules which i wrote above, and run it using the command line as follows:
python3 server.py
but it gives me some module related errors.
Crypto.Cipher.IDEA isn't available. You're probably using the Debian
pycrypto version. Install the original pycrypto for IDEA.
Traceback (most recent call last):
File "serverRsa.py", line 10, in <module>
from CryptoPlus.Cipher import IDEA
File "/home/pi/.local/lib/python3.5/site-
packages/CryptoPlus/Cipher/IDEA.py", line 4, in <module>
import Crypto.Cipher.IDEA
ImportError: No module named 'Crypto.Cipher.IDEA'
i tried it using the pip install PyCrypto and using the same with pip3.
and then run the same code but same error occurred.
Actually problem statement is to auto discover of all the nearby ip's
using the python programming , where i run the code on Raspberry Pi and
make it as a hotspot and other Pi boards act as client. Now when the
server found the client or discover them then it register them using some
key or encryption method.
i just need or code that passes some message to client using RSA but it seems the code have error.
Anyone please fix this issue.

Crypto.Cipher doesn't have any attribute named: IDEA.
import Crypto.Cipher.IDEA #won't work -_-
Maybe what you are looking for is CryptoPlus:
import CryptoPlus.Cipher.IDEA

If you really need an IDEA cipher in Python 2, and it's OK for you that it's slow (much slower than if it was implemented in C), there is one here: https://pastebin.com/hTn5K3Tx . Use it like this:
cb = IDEA('2bd6459f82c5b300952c49104881ff48'.decode('hex'))
plaintext, ciphertext = 'f129a6601ef62a47'.decode('hex'), 'ea024714ad5c4d84'.decode('hex')
assert cb.encrypt(plaintext) == ciphertext
assert cb.decrypt(ciphertext) == plaintext
Please note that the last patent on IDEA expired in 2012, and now IDEA is free to use for the public.

Standard Crypto Ciphers installed with pip install pycrypto now is version 2.6.1 and because of license restrictions it doesn't include IDEA (Crypto.Cipher.IDEA)
If you want to install Crypto.Cipher.IDEA you must find pycrypto-2.0.1 (freely available for download) which was last used to embedded this crypto cipher see pts comment above. Then follow the standard procedure to install the package pycrypto
python setup.py install
Problem appear if want to install IDEA for pyton3.

Related

PySerial Attribute Error with 'read_until'

I need some help troubleshooting an Attribute Error in my Python code.
I am working with a serial device connected by a /dev/ttyUSB0 to a Raspberry Pi 2B. My goal for this code is to read live serial data continuously from the serial device and separate out commands delineated by an '#' symbol instead of /n or /r.
This project is still in its early stages but from some quick research I've done the pyserial attribute 'read_until' would work perfectly as its backbone. This would allow me to read in one byte at a time and stop at an '#' symbol, and afterwards process the data before moving on to the next portion of serial data.
For some reason I get an Attribute Error when I try to use 'read_until' claiming that the 'Serial' object does not have this function. Below is the test code I am using and the error it spit back out:
import serial
gc = serial.Serial('/dev/ttyUSB0', baudrate = 230400)
print(gc.name)
def getCommand():
gcData = gc.read_until('#', 1).decode('ascii')
print(gcData)
getCommand()
gc.close()
And here is the output that this code gave me:
>>>
/dev/ttyUSB0
Traceback (most recent call last):
File "/home/pi/Python/GC/serialRead1.py", line 10, in <module>
getCommand()
File "/home/pi/Python/GC/serialRead1.py", line 7, in getCommand
gcData = gc.read_until('#', 1).decode('ascii')
AttributeError: 'Serial' object has no attribute 'read_until'
>>>
The frustration behind this is that 'read_until' should have been imported along with the serial library. Perhaps I am missing something quite simple, but it would be very helpful if I could use this attribute. Most other questions about 'read_until' are referencing the 'telnetlib' which as far as I know is not the same as what PySerial has.
Here is a link to the website where I found the documentation saying that 'read_until' should belong to PySerial: https://pyserial.readthedocs.io/en/latest/pyserial_api.html
Just so you are aware, I am very new to programming in general. Some of the jargon that seasoned programmers like yourselves use might go over my head and so I may have no idea how to perform the solutions you have. I ask for your patience as I learn more about programming and Python in general.
Thank you very much for your time!
It seems you have PySerial version 2.6 installed. This version was released in 2011, while the read_until method was added in 2015.
The easiest way to install the latest version (as you've discovered) is to use pip:
sudo apt install python3-pip
python3 -m pip install --user pyserial
Note that using pip with sudo is bad practice.
It's best to use a virtual environment or to use the --user flag, as demonstrated above.

Erwin API with Python

I am trying to get clear concept on how to get the Erwin generated DDL objects with python ? I am aware Erwin API needs to be used. What i am looking if what Python Module and what API needs to used and how to use them ? I would be thankful for some example !
Here is a start:
import win32com.client
ERwin = win32com.client.Dispatch("erwin9.SCAPI")
I haven't been able to browse the scapi dll so what I know is from trial and error. Erwin publishes VB code that works, but it is not straightforward to convert.
Install pywin32 (run the below from pip folder e.g. c:\Program Files\Python37\Scripts)
python -m pip install pywin32
python pywin32_postinstall.py -install
Sample script to extract DDL using Erwin's Forward Engineer functionality (change paths accordingly):
import win32com.client
api = win32com.client.Dispatch("erwin9.SCAPI")
unit = api.PersistenceUnits.Add("c:/models/data_model.erwin", "RDO=Yes")
unit.FEModel_DDL("c:/scripts/ddl_script.sql")
For the above to work, Erwin application should be running (probably).

Read Gmail messages using Python script as a cronjob

I'm having a problem accessing Gmail account. Currently, I'm using this library written in python 2.7+ to log in and to read Gmail messages. To use the library, I had to enable Google 'insecure app'. Everything is working fine with this lib.
Now, I'm moving to python 3+, and I cannot use the lib anymore. Whenever I import the lib, it throws the following error:
import gmail
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/gmail-0.0.5-py3.6.egg/gmail/__init__.py", line 16, in <module>
File "/usr/local/lib/python3.6/site-packages/gmail-0.0.5-py3.6.egg/gmail/gmail.py", line 5, in <module>
ModuleNotFoundError: No module named 'utf'
I tried to overcome this problem by looking at a replacement module for 'utf' in python 3+ but I couldn't figure out what it is. How can I fix that?
Another problem is that I tried the official python lib provided by Google. Here is the link for the tutorial. I successfully completed the quick start example, but the script opened my browser, and I had to allow the access via the browser. In fact, I just want to create a cronjob to run my script periodically on my server without an UI. Does Google allow it?
Thank you very much.
The official API for Gmail that works in python 3
and there are a lot of guides for using it, for example:
https://github.com/abhishekchhibber/Gmail-Api-through-Python
But if you feel this is too complicated (I do), instead you may want to activate access using POP3 or IMAP from the Gmail settings panel.
Then use poplib or imaplib.
Example: https://docs.python.org/3/library/poplib.html#pop3-example
This is in general easier, more portable and uses packages already found in default python installs.
Edit:
The library you were using used IMAP access, not oauth.
Also to answer your "UTF" question: every string in python 3 is UTF8 by default, if you want to decode raw data, you should use 'mystring'.decode('utf-7'), etc.
Edit 2: looks like someone already did the work: https://github.com/charlierguo/gmail/pull/48
OK, I just saw the problem in the instructions:
So, I guess your only alternative is to stick with POP3/IMAP (which your program was already using).

Cannot use suds from VS with IronPython

I'm developing a WPF IronPython application with VS 2015. I have to send a SOAP call and to read the answer so I'm trying to get suds to work. Since both pip and easy_install failed to install it, I downloaded the sources, unzipped them, and put them in the site-packages folder. It worked, now I can see them from VS.
When I try to use these modules however the program crashes, this is what I have done:
from suds import *
from suds.client import Client
class Utils(object):
def doStuff(addr, mail):
cl = Client(addr, verify=False)
cl.service.authenticate(email)
cl.service.otherFunctions(...)
I know that not every module works with IronPython, so my question is: have I made some error? Or is it suds that doesn't work with IronPython? If the second, do you know of alternatives?
Thank you.

Thrift error while generating python client file

I'm new to Hbase and I would like to comunicate with it throught a python API which works with Thrift. I've followed this tutorial in order to install it properly on my machine, everything seemed to worked fine then I generated a .thrift file with the following command:
wget http://svn.apache.org/viewvc/hbase/trunk/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift\?view\=markup
-O hbase.thrift
Then I tried to generate my client like it's showed here but i get the following error message:
[ERROR:/home/tests/hbase/hbase.thrift:12] (last token was '<')
syntax error
[FAILURE:/home/tests/hbase/hbase.thrift:12] Parser error during include pass.
I tried to lookup on internet what was the cause of this error and found this paper, I tried to lookup in thriftl.ll to see if I could correct the error but I found that the correction was already present in the file.
What can I do more in order to make this work ?
Thank you !
EDIT:
I'm using thrift 0.9.0
Using a fairly recent Thrift version and more importantly the proper URL I was able to generate Python sources without errors.
Please check if your download is actually a Thrift file or if it is a HTML source. The error message sounds very much like that, since HTML pages typically start with an <, and the right Thrift file contains the first < at line 110 (within list<Mutation>), not around line 12.
PS: Why are you using such an old version? 0.9.1 was released a year ago and 0.9.2 is actually in the process of being released.
PPS: Actually, the referenced ticket THRIFT-1274 seems not have much to do with it. But maybe I'm overlooking something.

Categories