could you, please, help with bouncycastle for hash function GOST 34.311. Somehow results are diffferent from test vector.
Wiki says:
"GOST("The quick brown fox jumps over the lazy dog") =
77b7fa410c9ac58a25f49bca7d0468c9296529315eaca76bd1a10f376d1f4294"
when using Digest Gost 34.11:
var testString = "The quick brown fox jumps over the lazy dog";
var result = (new GOST3411.Digest()).digest(testString.getBytes());
var resHex2 = new BigInteger(1, result).toString(16);
assertEquals("77b7fa410c9ac58a25f49bca7d0468c9296529315eaca76bd1a10f376d1f4294", resHex2.toUpperCase());
got:
org.opentest4j.AssertionFailedError:
Expected :77b7fa410c9ac58a25f49bca7d0468c9296529315eaca76bd1a10f376d1f4294
Actual :9004294A361A508C586FE53D1F1B02746765E71B765472786E4770D565830A76
with 2012 version:
var testString = "The quick brown fox jumps over the lazy dog";
var result = (new GOST3411.Digest2012_256()).digest(testString.getBytes());
var resHex2 = new BigInteger(1, result).toString(16);
assertEquals("77b7fa410c9ac58a25f49bca7d0468c9296529315eaca76bd1a10f376d1f4294", resHex2.toUpperCase());
got :
AssertionFailedError:
Expected :77b7fa410c9ac58a25f49bca7d0468c9296529315eaca76bd1a10f376d1f4294
Actual :3E7DEA7F2384B6C5A3D0E24AAA29C05E89DDD762145030EC22C71A6DB8B2C1F4
Does BouncyCastle support origin GOST 34.311 - 95? What is correct way to calculate it?
BC is using the GOST R 34.11-2012 (streebog) version of the standard
$ rhash -G -m "The quick brown fox jumps over the lazy dog"
3e7dea7f2384b6c5a3d0e24aaa29c05e89ddd762145030ec22c71a6db8b2c1f4 (message)
The wikipedia samples are for the deprecated GOST R 34.11-94 version
$ rhash --gost94 -m "The quick brown fox jumps over the lazy dog"
77b7fa410c9ac58a25f49bca7d0468c9296529315eaca76bd1a10f376d1f4294 (message)
If you actually want the old one, you should probably ask for plain GOST3411Digest instead of GOST3411.Digest2012_256 which is the new one.
Related
I created a bullet list with OpenXML. However, I can't figure out how to enable indentation when tab is pressed on a bullet.
Here is the code snippet to create bullet rows:
var abstractLevel1 = new Level(new NumberingFormat() {Val = NumberFormatValues.Bullet}, new LevelText() {Val = "●"}) {LevelIndex = 0};
var abstractLevel2 = new Level(new NumberingFormat() {Val = NumberFormatValues.Bullet}, new LevelText() {Val = "○"}) {LevelIndex = 1};
var abstractLevel3 = new Level(new NumberingFormat() {Val = NumberFormatValues.Bullet}, new LevelText() {Val = "■"}) {LevelIndex = 2};
var abstractNum1 = new AbstractNum(abstractLevel1, abstractLevel2, abstractLevel3) {AbstractNumberId = abstractNumberId};
In the created document, when I try to create a sub/nested bullet by hitting tab, it results in the following:
● Apples
○ Green Apples
● Pears
The bullet type changes as I expect but the indentation is wrong for Green Apples.
I took a document that has a working bullet list and converted it to an XML. Here is the section for the bullet list style:
<text:list-style style:name="WWNum1">
<text:list-level-style-bullet text:level="1" text:style-name="ListLabel_20_1" style:num-suffix="●" text:bullet-char="●">
<style:list-level-properties text:list-level-position-and-space-mode="label-alignment">
<style:list-level-label-alignment text:label-followed-by="listtab" fo:text-indent="-0.25in" fo:margin-left="0.5in"/>
</style:list-level-properties>
</text:list-level-style-bullet>
<text:list-level-style-bullet text:level="2" text:style-name="ListLabel_20_2" style:num-suffix="○" text:bullet-char="○">
<style:list-level-properties text:list-level-position-and-space-mode="label-alignment">
<style:list-level-label-alignment text:label-followed-by="listtab" fo:text-indent="-0.25in" fo:margin-left="1in"/>
</style:list-level-properties>
</text:list-level-style-bullet>
<text:list-level-style-bullet text:level="3" text:style-name="ListLabel_20_3" style:num-suffix="■" text:bullet-char="■">
<style:list-level-properties text:list-level-position-and-space-mode="label-alignment">
<style:list-level-label-alignment text:label-followed-by="listtab" fo:text-indent="-0.25in" fo:margin-left="1.5in"/>
</style:list-level-properties>
Notice the properties fo:text-indent and fo:margin-left. These properties are missing in the XML document produced by my code. I suspect this is the reason why sub/nested bullets are not being indented as shown in the example above. I searched through the OpenXML documentation and I could not find any information on these 2 properties. Which OpenXML class is responsible for those properties? I'm sure I need to add another argument when I instantiate a Level class but I could not figure out from the doc what it needs to be. Any ideas?
So far I've tried playing around with the ParagraphStyleIdInLevel and Indentation classes to no success.
I am following up on Indent lines of text using Xtext formatting API to ask a slightly different question, now that I know more about what I'm talking about.
I am having trouble using the formatting2 API to indent elements which get assigned to a list.
Here is a full example that demonstrates the problem:
MyDsl.xtext
grammar org.xtext.example.mydsl.MyDsl hidden(WS)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
greeting=Greeting
;
Greeting:
'Hello' ','? name=SIMPLE_WORD '!' NL+
lines+=Line*
;
Line: {Line}
SIMPLE_WORD+
NL
;
terminal SIMPLE_WORD:
('0'..'9' | 'a'..'z' | 'A'..'Z')
('0'..'9' | 'a'..'z' | 'A'..'Z' | '-' | '_')*
;
terminal NL: ('\r'? '\n');
terminal WS: (' ' | '\t');
MyDslFormatter.xtend
class MyDslFormatter extends AbstractFormatter2 {
#Inject extension MyDslGrammarAccess
def dispatch void format(Model model, extension IFormattableDocument document) {
model.greeting.format()
println(document)
}
def dispatch void format(Greeting greeting, extension IFormattableDocument document) {
for (line : greeting.lines) {
line.format()
line.prepend[indent]
}
}
def dispatch void format(Line line, extension IFormattableDocument document) {
// TODO...
}
}
MyDslFormattingTest.xtend
#RunWith(XtextRunner)
#InjectWith(MyDslInjectorProvider)
class MyDslFormattingTest {
#Inject extension FormatterTestHelper
#Test
def void indentLines() {
assertFormatted[
toBeFormatted = '''
Hello, World!
The quick brown fox
Jumps over the lazy dog
'''
expectation = '''
Hello, World!
The quick brown fox
Jumps over the lazy dog
'''
]
}
}
Output:
----------- RootDocument with ITextReplacers (syntax: <offset|text>) -----------
Hello, World!
<14|>The quick brown fox
<34|>Jumps over the lazy dog
--------------------------------------------------------------------------------
14 0 "": HiddenRegionReplacer: indentInc=1;indentDec=1
34 0 "": HiddenRegionReplacer: indentInc=1;indentDec=1
Test fails due to no indentation.
I have tried many ways to go about this, but every time I think I have something that will work, it will always lead to the indentInc=1;indentDec=1 result, causing indentation to cancel out.
Any ideas what I'm doing wrong, or how to go about solving this?
Cheers and thank you!
I was able to get the test to pass with
def dispatch void format(Greeting greeting, extension IFormattableDocument document) {
val begin = greeting.regionFor.ruleCallTo(NLRule)
val end = greeting.lines.last.regionFor.ruleCallTo(NLRule)
interior(begin, end)[indent]
for (line : greeting.lines) {
line.format
line.prepend[indent]
}
}
Answer courtesy of Tamás on the Xtext community forum.
I'm very new to programming and I'm currently learning Python 3.X.
I'm keeping everything I learn separated in files while trying to make it neat and interactive.
So I created a file only about boolean variables and its operations, and I wrote the following exercise:
# Variables
sad = bool(input("Are you sad? "))
hungry = bool(input("Are you hungry? "))
tired = bool(input("Are you tired? "))
# Process
print("\nYou are sad, and hungry, and tired: ", sad and hungry and tired)
print("You are tired or hungry, but happy: ", (sad or hungry) and not sad)
print("You're not tired, or you're hungry or happy: ", not tired or hungry or not sad)
# Input:
sad = True
hungry = False
tired = False
# Output:
You are sad, and hungry, and tired: True .......**should be False**
You are tired or hungry, but happy: False
You're not tired, or you're hungry,
I tried to put parenthesis between each pair of variables, but I'm getting the same output. What's happening? Am I not supposed to do this bool chain?
I've read a little about sed and awk, and understand that both are text manipulators.
I plan to use one of these to edit groups of files (code in some programming language, js, python etc.) to make similar changes to large sets of files.
Primarily editing function definitions (parameters passed) and variable names for now, but the more I can do the better.
I'd like to know if someone's attempted something similar, and those who have, are there any obvious pitfalls that one should look out for? And which of sed and awk would be preferable/more suitable for such an application. (Or maybe something entirely else? )
Input
function(paramOne){
//Some code here
var variableOne = new ObjectType;
array[1] = "Some String";
instanceObj = new Something.something;
}
Output
function(ParamterOne){
//Some code here
var PartOfSomething.variableOne = new ObjectType;
sArray[1] = "Some String";
var instanceObj = new Something.something
}
Here's a GNU awk (for "gensub()" function) script that will transform your sample input file into your desired output file:
$ cat tst.awk
BEGIN{ sym = "[[:alnum:]_]+" }
{
$0 = gensub("^(" sym ")[(](" sym ")[)](.*)","\\1(ParameterOne)\\3","")
$0 = gensub("^(var )(" sym ")(.*)","\\1PartOfSomething.\\2\\3","")
$0 = gensub("^a(rray.*)","sA\\1","")
$0 = gensub("^(" sym " =.*)","var \\1","")
print
}
$ cat file
function(paramOne){
//Some code here
var variableOne = new ObjectType;
array[1] = "Some String";
instanceObj = new Something.something;
}
$ gawk -f tst.awk file
function(ParameterOne){
//Some code here
var PartOfSomething.variableOne = new ObjectType;
sArray[1] = "Some String";
var instanceObj = new Something.something;
}
BUT think about how your real input could vary from that - you could have more/less/different spacing between symbols. You could have assignments starting on one line and finishing on the next. You could have comments that contain similar-looking lines to the code that you don't want changed. You could have multiple statements on one line. etc., etc.
You can address every issue one at a time but it could take you a lot longer than just updating your files and chances are you still will not be able to get it completely right.
If your code is EXCEEDINGLY well structured and RIGOROUSLY follows a specific, highly restrictive coding format then you might be able to do what you want with a scripting language but your best bets are either:
change the files by hand if there's less than, say, 10,000 of them or
get a hold of a parser (e.g. the compiler) for the language your files are written in and modify that to spit out your updated code.
As soon as it starts to get slightly more complicated you will switch to a script language anyway. So why not start with python in the first place?
Walking directories:
walking along and processing files in directory in python
Replacing text in a file:
replacing text in a file with Python
Python regex howto:
http://docs.python.org/dev/howto/regex.html
I also recommend to install Eclipse + PyDev as this will make debugging a lot easier.
Here is an example of a simple automatic replacer
import os;
import sys;
import re;
import itertools;
folder = r"C:\Workspaces\Test\";
skip_extensions = ['.gif', '.png', '.jpg', '.mp4', ''];
substitutions = [("Test.Alpha.", "test.alpha."),
("Test.Beta.", "test.beta."),
("Test.Gamma.", "test.gamma.")];
for root, dirs, files in os.walk(folder):
for name in files:
(base, ext) = os.path.splitext(name);
file_path = os.path.join(root, name);
if ext in skip_extensions:
print "skipping", file_path;
else:
print "processing", file_path;
with open(file_path) as f:
s = f.read();
before = [[s[found.start()-5:found.end()+5] for found in re.finditer(old, s)] for old, new in substitutions];
for old, new in substitutions:
s = s.replace(old, new);
after = [[s[found.start()-5:found.end()+5] for found in re.finditer(new, s)] for old, new in substitutions];
for b, a in zip(itertools.chain(*before), itertools.chain(*after)):
print b, "-->", a;
with open(file_path, "w") as f:
f.write(s);
I'm running into a problem using the SnowBallAnalyzer in Lucene.NET. It works great for some words, but others it doesn't find any results on at all, and I'm not sure how to dig into this further to find out what is happening. I am testing the search on the USDA Food Description file which can be found here (http://www.ars.usda.gov/SP2UserFiles/Place/12354500/Data/SR23/asc/FOOD_DES.txt). I'm using the English stemming algorithm. I get the following results when searching for "eggs":
Bagels, egg
Bread, egg
Egg, whole, raw, fresh
Egg, white, raw, fresh
Egg, yolk, raw, fresh
Egg, yolk, raw, frozen
Egg, whole, cooked, fried
...
Those results are great. However I get no results at all when searching for "apple". When I use the StandardAnalyzer, and search for "apple" I get the following results.
Croissants, apple
Strudel, apple,
Babyfood, juice, apple
Babyfood, apple-banana juice
...
Not the best results, but at least it's showing something. Anyone know why the stemming analyzer would be filtering in such a way that I would not get any results?
Edit: Here is my prototype code that I'm working with.
static string[] Search(string searchTerm)
{
//Lucene.Net.Analysis.Analyzer analyzer = new Lucene.Net.Analysis.Snowball.SnowballAnalyzer("English");
Lucene.Net.Analysis.Analyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer();
Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", analyzer);
Lucene.Net.Search.Query query = parser.Parse(searchTerm);
Lucene.Net.Search.Searcher searcher = new Lucene.Net.Search.IndexSearcher(Lucene.Net.Store.FSDirectory.Open(new DirectoryInfo("./index/")), true);
var topDocs = searcher.Search(query, null, 10);
List<string> results = new List<string>();
foreach(var scoreDoc in topDocs.scoreDocs)
{
results.Add(searcher.Doc(scoreDoc.doc).Get("raw"));
}
return results.ToArray();
}
Are you sure you used Lucene.Net.Analysis.Snowball.SnowballAnalyzer("English") to write your index ? You have to use the same analyzer to write and query the index.