Python code to recover private key from public key - public-key

Helllo,
I would like to use this code to generate/recover my private key, I'm using Python 3.6 and installed ecdsa package but how should I edit the code with my public key?
I'm quite new to python, tried some things but I get the following errors..
NameError: name 'addr' is not defined
TypeError: 'NoneType' object is not iterable
IndentationError: unexpected indent (<-- I have many of this error)
Do I need anything else to download and install?
I'd appreciate for any kind of help!

how should I edit the code with my public key?
You can't.
Private keys cannot be generated from public keys. This is absolutely fundamental to public key cryptography.
I get the following errors..
...
NameError: name 'addr' is not defined
You must define or initialize addr before using it.
TypeError: 'NoneType' object is not iterable
See TypeError: 'NoneType' object is not iterable in Python
IndentationError: unexpected indent
Python depends on indentation as part of its syntax, for example indentation is used to define blocks where other languages might use { and } or begin and end.
If you have too much or too little indentation it alters the meaning of the code and may not make any sense. You must pay careful attention to indentation when using Python.
In particular, I suspect that if you set tab-spacing to other than 8 and irregularly mix tabs with spaces in indentation, you will have problems.

Related

Testing type matching differences in Java 6 and Java 8

I updated an application JDK from 1.6 to 1.8 but I kept the language level 1.6 in IntelliJ.
After updating I got compilation error in some tests in assertThat statements with checking type of an object. The code is like this:
assertThat((Class) myList.get(0).getMyClassType(), is(equalTo(MySubclass.class)));
myList is looking like this:
List<MyClassDefinition> myList = myClassDefinition.getMyClassDefinitions(reader);
Where definition of MyClassDefinition and getMyClassType() are like this:
public class MyClassDefinition {
private Class<? extends MyClass> classType;
public Class<? extends MyClass> getMyClassType() {
return classType;
}
}
and MySubclass is Myclass's subclass:
public class MySubclass extends MyClass {
#Override
public void initialise() {
// some action here!
}
}
The definition of MyClass is
public abstract class MyClass extends AnotherClass<AnotherType>{
//Definitions
}
The import for Assert is and equals library is this:
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
and the hamcrest version is hamcrest-all-1-3
After changing project SDK to jdk 1.8 I am getting this error message:
Error:(136, 9) java: no suitable method found for assertThat(java.lang.Class,org.hamcrest.Matcher<java.lang.Class<MySubClass>>)
method org.hamcrest.MatcherAssert.assertThat(java.lang.String,boolean) is not applicable
(argument mismatch; java.lang.Class cannot be converted to java.lang.String)
method org.hamcrest.MatcherAssert.<T>assertThat(java.lang.String,T,org.hamcrest.Matcher<? super T>) is not applicable
(cannot infer type-variable(s) T
(actual and formal argument lists differ in length))
method org.hamcrest.MatcherAssert.<T>assertThat(T,org.hamcrest.Matcher<? super T>) is not applicable
(cannot infer type-variable(s) T
(argument mismatch; org.hamcrest.Matcher<java.lang.Class<MySubClass>> cannot be converted to org.hamcrest.Matcher<? super java.lang.Class>))
application is build with Ant and we have added hamcrest jar file to class file, so there is no change when we are altering JDK in project.
So my question is why this code is working with JDK 1.6 but not working with 1.8 while I am using same level of language (1.6) for compilation? Is it depend to different libraries some how?
Apparently, you had a problem with the generic type signatures which you worked around by inserting a type cast to the raw type Class, which causes the compiler to treat the entire statement as an unchecked operation using raw types only.
As you can see from the compiler message, org.hamcrest.Matcher<java.lang.Class<MySubClass>> cannot be converted to org.hamcrest.Matcher<? super java.lang.Class>, it now did a generic type check which (correctly) failed, but imho, it shouldn’t do that type check under Java 6 language rules. The problem stems from the fact that JDK8 doesn’t include the original Java 6 compiler but rather let the new compiler attempt to compile using the old rules, which may not be that precise.
But regardless of whether the behavior is correct or not, I wouldn’t expect a fix for it, as emulating the old Java 6 language rules is not of a high priority.
Note that with source level 1.8, the code compiles without problems, even without the raw type cast. The original problem stems from the restrictive signature of CoreMatchers.equalTo(…). The standalone expression equalTo(InstanceOfFoo) returns a Matcher<Foo>, which being passed to assertThat allows to only test instances of Foo (it’s even worse when using isA(Foo.class) which also can only test instances of Foo, which makes the test pointless).
With Java 8, there is target type inference, which allows, e.g.
Matcher<Object> m = equalTo(InstanceOfFoo);, which will infer Object for <T> and passes, as InstanceOfFoo is also assignable to Object. This also works in conjunction with the compound assertThat statement of your question, inferring a suitable type.
This guides us to the general solution that works with all language levels. Just use
assertThat(myList.get(0).getMyClassType(), is(equalTo((Object)MySubclass.class)));
Class<MySubclass> is, of course, assignable to Object which makes the cast a no-op. But then, getting a Matcher<Object>, you can check every object you like, including the result of myList.get(0).getMyClassType(), which is, of course, also assignable to Object. Unlike your original workaround, this doesn’t bear any raw type usage nor unchecked operation.
You could also use an explicit type instead of a cast, CoreMatchers.<Object>equalTo(MySubclass.class), but this eliminates the benefit of import static.
By the way, when matching Class objects, you may use sameInstance instead of equalTo.

::itcl::delete throws error "invalid command name"

I am using itcl delete command to delete objects and classes. However, tcl interpreter says "invalid command name "delete". Here is the partial code snippet.
% itcl::find classes
datapath point datapath_point
itcl::find objects
datapath_point0 datapath_point1 datapath0
% itcl::delete object datapath_point0
invalid command name "delete"
Thanks,
boppu
With Peter, comments I could look for the Error in my code. In one of the base class, I had the following code.
destrutor {
delete object $this
}
Here, delete namespace was missing. Even though you add "itcl::delete", you will endup in another error. Simple and correct solution should be an empty destructor.
destructor {
}

JRuby: Documentation of mappings/conversions between Java and Ruby types/classes?

I am writing a Java wrapper library around a ruby gem so I am embedding ruby within Java and not the other way around. I seem to be in the vast minority!
If I have a ruby method that returns a Time object then I can very easily convert it into a java.util.Date object on the Java side like this:
public Date getStartTime() {
IRubyObject result = RuntimeHelpers.invoke(runtime.getCurrentContext(),
this, "start_time");
return (Date) result.toJava(Date.class);
}
But I think I got lucky working this out by trial and error and not all like-seeming types can be converted in this way. I have another ruby method that returns a URI object (it could be a URI::HTTP or a URI::HTTPS in fact) but trying the obvious (given the above) conversion to a java.net.URI doesn't work (I also tried it with java.net.URL):
public URI getUri() {
IRubyObject result = RuntimeHelpers.invoke(runtime.getCurrentContext(),
this, "uri");
return (URI) result.toJava(URI.class);
}
This code compiles, but fails at run time:
Exception in thread "main" org.jruby.exceptions.RaiseException: (TypeError) cannot
convert instance of class org.jruby.RubyObject to class java.net.URI
I realise that in ruby a URI is actually a module and URI::HTTPS, etc are the classes, so I'm not entirely surprised that the above didn't work. But there's clearly a bit of internal "magic" being done for the Time/Date example so I was wondering if there were similar conversions provided for other types, which types and where they are documented.
Any pointers much appreciated.
https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby says "Conversion of Types – Ruby to Java – See the JRuby rspec source code dir spec/java_integration for many more examples. [examples, ...]".
Sure enough, coercion_spec.rb contains a lot of examples/specifications. Here's the case you already use:
describe "Time\"to_java" do
describe "when passed java.util.Date" do
it "coerces to java.util.Date" do
t = Time.now
d = t.to_java(java.util.Date)
d.class.should == java.util.Date
end
end
# [...]
end
I believe this is the best documentation currently available.

Why do I get a "Too many input arguments" error when not passing any?

I am working on some simple object-oriented code in MATLAB. I am trying to call one of my class methods with no input or output arguments in its definition.
Function definition:
function roll_dice
Function call:
obj.roll_dice;
When this is executed, MATLAB says:
??? Error using ==> roll_dice
Too many input arguments.
Error in ==> DiceSet>Diceset.Diceset at 11
obj.roll_dice;
(etc...)
Anyone have any ideas what could be causing it? Are there secret automatic arguments I'm unaware that I'm passing?
When you make the call:
obj.roll_dice;
It is actually equivalent to:
roll_dice(obj);
So obj is the "secret" automatic argument being passed to roll_dice. If you rewrite the method roll_dice to accept a single input argument (even if you don't use it), things should work correctly.
Alternatively, if you know for sure that your method roll_dice is not going to perform any operations on the class object, you can declare it to be a static method as Dan suggests.
For more information on object-oriented programming in MATLAB, here's a link to the online documentation.
I believe you can also get around this by declaring roll_dice to be a static method.

How do I find character positions in ANTLR 2?

I have a simple grammar, and have produced a pair of c# classes using antlr 2.7.7. When the parser finds an error with a token, it throws an exception; I want to find out how many characters into a parsed stream the token came. How do I do that?
It's been a long time ago since I played with ANTLR, but if I remember well, to do what you want, I had to subclass the parser to keep a counter of characters that was incremented each time a new token was found (with the token length of course).
You ought to read chapter 10 ("Error Reporting and Recovery") from Terrence Parr's book "The Definitive ANTLR Reference".
Not knowing what target language you're using, it'll be hard to tell you exactly what to do. But I'll assume you're using the Java target, and you can correct me if I'm wrong.
When an ANTLR recognizer fails to match an input string, it throws a very specific exception, based on the failure context. (There are nine different kinds of exceptions, RecognitionException is the root type, and it has eight subclasses of its own: MismatchedTokenException, MismatchedTreeNodeException, NoViableAltException, EarlyExitException, FailedPredicateException, MismatchedRangeException, MismatchedSetException, MismatchedNotSetException).
The root exception type (RecognitionException) has a few handy public fields that you might want to take a look at (specifically: "index", "line" and "charPositionInLine"). The "index" field tells you the exact character position where the error was found. The "line" and "charPositionInLine" fields are pretty self-explanatory. Here's the JavaDoc:
http://www.antlr.org/api/Java/classorg_1_1antlr_1_1runtime_1_1_recognition_exception.html