How to solve a hash function? - hash

I am totally lost on the below question and was wondering if someone might be able to point me in the right direction on here.
"Consider the hash function h(i) = (i + 5) mod 7, and suppose it is used in an implementation of the S/Key protocol. Let the seed be value 0, and suppose that the first password the user returns after the initialization step is 4.
What password does the user return on the third login counting the first login password as 4."
Any ideas?

Related

how to write a text and calculation in a same time like Calcnote app in Flutter

I try lots of things but I failed kindly help me with how to do this and please someone shares a complete. I also share a screenshot of the original app I making same like this app.
App description:
1:When typing or calculating on the app if the user needs the next line and show a list num
2: The most important thing is when we calculate any num can we write something in the same type ( you think it's a notepad + calculator)?
3: Also when we write and type 5 + 5 we don't need to press = equal to. they abstract and subtract automatically.
thank you so much for your support.

FBD for TwinCat Beckhoff... Function Block Input Output How is this working

Seems IW_PR_Schrittnummer is only referenced in 3 spots... where it's declared and where its read in the fbd routine... I guess what I'm asking is something writing a number to this variable... or what? If so how would I find it... also what is the action being performed by this first function block? looks like there are 4 inputs, Auto, is Auto Active, does tasknumber = 0, and is Press Free. if all 4 of these are true... then End Auto. Does that sound right??? someone else programmed this for a job that does work. The tags are in German.
1st FBD
Variable Reference
Variable Declaration
2nd fbd just for reference
The IW_PR_Schrittnummer is linked to input I/O using AT %ID716 command. So it gets its value from I/O memory. That basically means that "take this value from input memory at address 716 and the size is D (double word, 32 bits).
I'm not sure how you can check what is in that address when it's defined with direct addressing like this. Hopefully someone else knows a good tip for this!
More info about addresses: https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/18014401038842507.html&id=6547931155168793261
More info about addresses: https://help.codesys.com/webapp/_cds_at_declaration;product=codesys;version=3.5.15.0
That logic from your 1st image works as you said. So AutoFinde will be TRUE, if Auto, AutoAktiv, IstFrei are all TRUE and the input IW_PR_Schrittnummer is 0. Otherwise the AutoFinde will always be FALSE.

In Hartl's tutorial, Listing 8.49, why is there a "forget(user)" option?

This is in relation to the checkbox that allows users to stay logged in when they close their browser. In an intermediate version, we remembered the user regardless, and now we're checking the params to see if the checkbox was set. This is the line of code that confuses me:
params[:session][:remember_me] == '1' ? remember(user) : forget(user)
Specifically, why are we forgetting the user if params[:session][:remember_me] is 0? Since we have never remembered the user (I think -- I'm a major newbie), wouldn't this work:
remember(user) if (params[:session][:remember_me] == '1')
and make more sense? I tried it and it passes the tests (which are very basic), but it also seems to behave appropriately. But maybe there's some stray variable that's staying set that I'm missing because I don't know what I'm doing.
I am at the exact same point and was wondering about the exact same thing.
And I came to the conclusion: it's only about security.
Because if an user never logs out of your app, an attacker who stole her user_id and remember_token cookies could use them all the time. However if the user eventually logs in on another computer either the remember_digest attribute gets a new value or is set to nil. Either way the attacker gets locked out.
By omitting forget(user) the only time the remember_digest is set to nil is when the user deliberately logs out.
However the version remember(user) if (params[:session][:remember_me] == '1') gives the user the ability to select one "remembered" computer.

How can I get statements within functions to execute in a randomly chosen order?

I'm relatively new to Matlab, and I've been trying to solve my problem for ages but I'm just continuously arriving at a dead end.
I have a code which should, in theory, play 3 sounds in a random order (each order being different for each trial). Upon each sound playing the participant will be asked which sound they heard and then given feedback. I have all the code complete and working up until the random order part. I have created code that on each trial will randomly order 1,2 and 3.
Order = [1, 2, 3];
PhonemeOrder = randperm (numel(Order));
I then have a function which plays the sound/asks the questions etc. within this I have attempted switch cases statements and if else statements depending on the number that PhonemeOrder produces but the order doesnt change even when phoneme order does. I believe my problem is however that PhonemeOrder comes out like [1,2,3] or [3,1,2] which is what i wanted. but Im not sure how to get my sounds to play in the order that it shows because I am using code like...
if/ PhonemeOrder = 1;
then do this...
elseif phonemeorder = 2;
then do this...
else
do this...
Or I've tried code like
switch cases
case 1
do this
case 2
do this
case 3
do this
I'm guessing this is where i am going wrong, but i just dont know how to change it and make it work! I hope this makes sense? I just need it to play in the order that phonemeorder specifies, with the order changing on each trial.
Any help will be greatly appreciated :D
bexG,
I think you are on the right track.
The only thing you need is to use a "for-loop" to go through the array of PhonemeOrder.
for i=1:length(PhonemeOrder)
switch PhonemeOrder(i)
case 1
play the first song
case 2
play the second song
case 3
play the thrid song
end
end
I hope this will help.
Please let me know if you have any further question.

KbWait won't register key press

I'm trying to collect keyboard data, but I can't get KbWait to work. In the following code, I'm trying to wait for the participant to respond, check if their response is one of two acceptable answers, and then continue. It should only continue when the participant presses 'j' or 'f'.
response = [];
while isempty(response)&&(GetSecs - FlipTimestamp) < 10
[keyIsDown, RTsecs, RTkeyCode, deltaSecs] = KbWait;
if keyIsDown
r=find(RTkeyCode);%this should be the code for the key pressed
response=KbName(r);%Figure out what key was pressed
rt=num2str(RTsecs-time); %subtract off timestamp from when window was flipped
if response == 'f'
match_response= false;
end
if response == 'j'
match_response= true;
end
end
end
However, KbWait never returns. When I try to run it from the command line, it doesn't work either. It just hangs up and refuses to return, and I have to interrupt the program.
It's been nine months since you posted this, so I imagine you've already found some sort of solution. But I was also having this problem, and here's what I discovered:
I went through my entire HID list: devices = PsychHID('Devices')
As I examined each one's 'usageName' property, I found that multiple devices were considered to be 'Keyboard', even though I only have one actual keyboard connected.
I then tried each one's index as an argument for KbWait. When I got to the correct one, KbWait worked.
Hi there I think your problem is the KbWait function.
you used KbWait like ist KbCheck but the output of those functions is different
[secs, keyCode, deltaSecs] = KbWait([deviceNumber][, forWhat=0][, untilTime=inf])
[keyIsDown, secs, keyCode, deltaSecs] = KbCheck([deviceNumber])
Try KbCheck its more exact than KbWait, because KbWait checks the keyboard only every 5 ms
Here is a Function I wrote sometimes ago: working KbCheck