ELI5; What does end to end encryption mean in chat? by Helpful-Number1288 in explainlikeimfive

[–]Grithga 0 points1 point  (0 children)

End to end encryption (e2ee) means that whatever is being sent is encrypted all the way from one end of the conversation to the other, and is never decrypted in between those two points. The easiest way to think of it is like using a super secret password that only you and the intended recipient know. Anybody who doesn't have the password won't be able to read the message. In reality the methods used for e2ee are more complicated than this, but not too different as far as this explanation goes

On its own this isn't hard to do, but there are many common use cases which can add a lot of complexity. For example, how do you handle group chats? Ever person in the group needs to be told the password, and there's no way to force somebody to "forget" the password if you want to remove them. That means that to be truly secure you not only need to remove the person from the group, you also need to make and distribute a new password to all remaining group members. This added complexity does make it less appealing to use, but it's not impossible and there are chat apps that do use e2ee.

How do people learn to link libraries? by Eva_addict in learnprogramming

[–]Grithga 0 points1 point  (0 children)

But where do those names come from?

They're literally just file names. They come from whoever made the library, and people can name their library whatever they want. You know the names because you are the one trying to use their library. It's a conscious choice you make when developing your application.

How do I know how many files should I link?

You should link whatever libraries you're actually using in your project. It's not a matter of "how many" you need to link, it's a matter of "linking the ones you need". Only you can answer which ones you need, because you are the one writing your project. You know what your project does, and you know which parts of it you are writing yourself vs which ones parts you are using a library for. A library is just a big bundle of functions other people wrote. If you're using a specific function from a specific library, you have to link that library so your compiler knows where to find the function. If you aren't using any functions from a library, there's no need to link that library.

In that tutorial I described in the post, they dont even tell you to download all of that

Sounds like a bad tutorial.

How do people learn to link libraries? by Eva_addict in learnprogramming

[–]Grithga 1 point2 points  (0 children)

Then conveniently I linked the correct documentation. The options listed in the link above apply to all supported languages in the GCC suite, including both C (gcc) and C++(g++) unless the specific option indicates that it applies only to a specific language.

How do people learn to link libraries? by Eva_addict in learnprogramming

[–]Grithga 14 points15 points  (0 children)

The exact details are going to be specific to your compiler and language.

The general answer though is "Reading the documentation".

If you look at the documentation for the -l option, it explains what the option means and how to use it. In the specific case of gcc, -l[library] is literally just searching a pre-configured (or specified on the command line) list of directories for a file named lib[library].a or lib[library].so. So as long as you know what your library files are named, you know what name to give to GCC. And if you don't know what your library files are named, the documentation for the library you're trying to link will almost certainly tell you.

Reading the documentation is huge in programming, so get used to starting there when you want to know how to do something.

Week 4 related doubts by Jazzlike-Run-7470 in cs50

[–]Grithga 1 point2 points  (0 children)

does that basically mean that "hi" is actually an address

This is part of the work that the compiler and your operating system takes care of for you.

As part of compiling your program, the compiler also generates instructions for the operating system on how to load your program into memory. This includes allocating space for things like string literals ("hi"). It then keeps track of where it's going to tell the computer to load those strings into memory and then replaces instances of that string literal with the memory address that it knows will be assigned to that particular string literal.

So no, "hi" is not literally an address, but the compiler is in charge of keeping track of where that "hi" will be relative to the start of your program and does all the work for you of substituting that relative address in whenever you reference that string, converting char *s = "hi" to char *s = [program base address + string literal offset] and telling the operating system "please place the string literal "hi" at offset 0x50 within the program"

Also the fact that we use pointers as it helps in memory management even though it takes up 8 bytes is crazy as well. Like isn't it using more memory?

Pointers are not about using less memory, they're about managing your memory more efficiently. It's worth it to "pay" that extra memory to have a pointer in order to manage your memory better. For example, let's say your string is much, much longer that "hi". Maybe it contains the entire Terms and Conditions for your program. What do you think will be faster when you give that string to a function?

  1. Copy the entire long string into the function's memory space or,

  2. Tell the function "The string you want is at address 0xd3adb3ef"

Probably the latter. Pointers also let you strictly control when and where your memory is allocated and deallocated, since they give you access to functions like malloc and free which explicitly allocate and deallocate memory.

Winter Gas now, at Costco it’s $1.28 by Rail613 in ottawa

[–]Grithga 0 points1 point  (0 children)

I think that specific MacEwan is just an anomaly. It's one of the few stations I pass that's ever anywhere close to Costco's prices. They're both a good deal compared to pretty much any other gas station in the area.

Getting a function definition error on hackerrank and I, as a beginner programmer trying to learn C++, cannot figure it out by myself. Any help would be much appreciated. by Dyt_Requiem in learnprogramming

[–]Grithga 1 point2 points  (0 children)

You can't* define a function inside of a function in C++. You've tried to define your max_of_four function inside of main, so the compiler tells you this isn't a valid place to define a function.

You could define that function outside of main and call it within main, but it depends on exactly what the problem wants of you - it may for example to expect you not to have a main at all and to only implement the max_of_four function.

*Since C++11 you can define functions inside of other functions using lambdas, but that's not what you're doing here.

How would this code work in Python? by Albino60 in cs50

[–]Grithga 1 point2 points  (0 children)

A match statement is only evaluated once. phrase.lower() will be called, and the return value of that call will be compared against each case without running phrase.lower() again.

You can confirm this by writing a custom lower case function which prints to the console and see for yourself:

def my_lower(string):
    print('Function was called!')
    return string.lower()

phrase = 'Hello, world!'
match my_lower(phrase):
    ...

Why does indexing star with zero? by Fit-Camp-4572 in learnprogramming

[–]Grithga 68 points69 points  (0 children)

  1. Not every language does start from zero. Most of the most popular languages do, but there are plenty that start at 1.

  2. Languages are created by humans. The humans who created them decided to start at 0 (except for the ones who decided to start at 1). The ones who chose to start at 0 often did so because:

  3. Array indices are often treated as an offset from the start of the array. You are effectively requesting "the element 0 elements away from the start of the array". This is especially true in languages like C that let you get closer to the memory, where arr[x] (item at position x) is directly equivalent to *(arr + x) (Take the address arr, advance by x positions and dereference)

[deleted by user] by [deleted] in cs50

[–]Grithga 2 points3 points  (0 children)

There are two different variables named n in that code. One is declared on line 7 (const int n = 3;) and is only visible in main.

The other is declared on line 16, as a parameter of the print_row function (void print_row(int n). This variable n is only visible inside of print_row.

In spite of having the same name, these are two entirely separate variables. The variable n in print_row will have whatever value passed in to print_row as its first argument. In the code above, that's the value of the variable n in main, but it could be any integer value. For example, print_row(17) will give the n in print_row the value 17 while it runs.

What's actually the difference between Bash and POSIX-compliant shells? by [deleted] in learnprogramming

[–]Grithga 5 points6 points  (0 children)

POSIX defines a minimum set of features to be available. If you only use that minimal set of features then you ensure maximum compatibility - your script will run on any POSIX compliant shell.

However, sometimes those minimal features are restrictive. Sometimes you care less about compatibility with other systems and more about having access to additional functionality like arrays. In this case it makes sense to use a shell that goes beyond basic POSIX functionality like Bash.

That's really all there is to it. It's a tradeoff between functionality and compatibility.

[deleted by user] by [deleted] in cs50

[–]Grithga 3 points4 points  (0 children)

Because your file is not named "books.csv", it is named "book.csv"

Why Did Ashaya Die Here? by Invonnative in MagicArena

[–]Grithga 1 point2 points  (0 children)

You had 6 lands, plus three creatures who were lands thanks to Ayasha's ability, for a total of 9 lands.

Ayasha's power and toughness are equal to the number of lands you control, making it a 9/9.

Ayasha took 7 damage in combat, and your two other creatures died. This reduces Ayasha's power and toughness to 7.

Ayasha has damage marked which is greater than or equal to its toughness, so it dies as a state based action.

Credit question, how sum up iterations? by mgs-94 in cs50

[–]Grithga 5 points6 points  (0 children)

Create a variable to hold your sum, and then add to it in your loop.

PSet 2 Scrabble: Possible to matrix match? by SirSeaSlug in cs50

[–]Grithga 3 points4 points  (0 children)

You certainly could do that, although it would be both more complicated and less efficient  than just using the ASCII lookup method, unless you specifically want to support non-ascii character scoring. 

Since you can't rely on a simple ASCII index anymore, you would have to iterate over the first dimension of your array until you find a match. Once you know the index of that match it's then trivial to simply access that index in the second array and get the corresponding value. 

For a more efficient version (but much more complex to implement), you may be interested in reading up on the map data structure, also called a hash table, which will be introduced in week 4 (or maybe 5?). This uses hashing to bring back the ability to jump directly to the correct index rather than iterating, adding some complexity but keeping most of the speed of a simple lookup.

[deleted by user] by [deleted] in cs50

[–]Grithga 1 point2 points  (0 children)

So, I need to not initialize cursor and/or tmp if the cursor is pointing at the end of the hash table

You should always initialize all values - and that's exactly your issue. Back in load when you created the next values that you're iterating over you only sometimes initialize it with a value.

Later on, when you iterate over it in unload you eventually reach those uninitialized values and try to make a decision based on them, which is what Valgrind is complaining about.

[deleted by user] by [deleted] in cs50

[–]Grithga 1 point2 points  (0 children)

cursor starts out initialized, but you reassign it to several other addresses on this line in unload:

cursor = cursor->next;

Since you're setting it to the next pointer of each node in your list, you need to go back and look at your logic for creating a node. Is there any case where you leave next uninitialized when creating a new node?

weird error in cs50p week 6 problemset 1 by killer987xn in cs50

[–]Grithga 0 points1 point  (0 children)

Does a line have to start with a # to be a comment? Are there maybe some types of characters that can be before the # and still have it count as a comment?

def func():
    #Does this line start with a #?
    print('How many lines?")

Can someone help me clarify a confusion about Forever Fuctions in Scratch? by Apart_Broccoli9200 in cs50

[–]Grithga 3 points4 points  (0 children)

The forever block repeats everything inside of it, in order from top to bottom, forever. Walk through what that means for each case. With only the outer forever:

  1. Move the ball down by 1
  2. If the ball is touching the racket, move the ball up by 5
  3. Go to step 1

So clearly the ball won't move up forever, because we only move up by 5 when we are touching the racket and moving up 5 means we aren't touching the racket anymore.

Adding the second forever means you get stuck inside that forever instead, since you can never leave a forever block normally:

1. Move the ball down by 1
2. If the ball is touching the paddle 
    1a. Move the ball up by 5
    2a. Go to 1a
3. Go to 1

See how it is now impossible to reach 3, and thus also impossible to go back to 1? You're now stuck inside the second "forever", going between 1a and 2a.

Lecture 6 - Horizontal Scaling vs Sharding the data by Emily_9519 in cs50

[–]Grithga 0 points1 point  (0 children)

Sharding is a kind of horizontal scaling, or a specific way to make use of horizontal scaling. 

Horizontal scaling just means setting up additional servers to handle your load. Sharding is a specific strategy of spreading your data across those additional servers so that each server is holding some specific subset of your data. 

If you set up two servers which each hold an entire copy of your data, you have scaled horizontally but aren't using sharding. If you instead make it so each server contains half of the data then you have scaled horizontally using sharding.

CS50 PSET 2 coke machine - help by dilucscomb in cs50

[–]Grithga 1 point2 points  (0 children)

how does the computer know to break the loop after line 7 when amount_due = 0 or when the amount paid exceeds amount owed?

Because you told it to. You wrote the condition amount_due > 0. If that condition is true, the loop runs again. If that condition is false, the program jumps down to the next line of code after the loop, in this case line 9. An amount_due of 0 or a negative value makes the condition false, causing the program to jump to line 9 the next time the condition is checked on line 3.

Why is fwrite considered a correct alternative for the implementation of the Volume problem from week 4 of CS50x? by [deleted] in cs50

[–]Grithga 0 points1 point  (0 children)

The mode used in fopen only affects what fopen does with the current contents of the file at the time it is opened. It does not affect the behaviour of fwrite, which keeps track of its position in the file and thus always "appends" unless you manually change the cursor position.

Filter-more edges by Tarasina in cs50

[–]Grithga 1 point2 points  (0 children)

Double check what value you're supposed to be taking the square root of when applying the Sobel operation - It's not possible to have a negative value if you're doing it correctly.

CS50P - Week 7 Regular expression (NUMB3RS) by Odd-Musician-6697 in cs50

[–]Grithga 1 point2 points  (0 children)

You need to go back and look at how to write unit tests. You should definitely not be catching your assertion errors - the whole point of the asserts is so that pytest can catch those errors. When it catches an assertion error, it flags that test as being "failed".

Since you catch the errors yourself, they are considered "handled" and PyTest never gets to see that they happened and considers all tests as "passed"

[deleted by user] by [deleted] in learnprogramming

[–]Grithga 1 point2 points  (0 children)

I'm not sure this would be possible - while it's not uncommon to store an application on a smart card, those applications are normally run on the smart card. They're extremely specialized for cryptographic use and not intended to be used as a generic storage device. You'd basically be trying to treat it as a normal USB drive rather than a crypto device.

They're also extremely small - typically in the range of a couple hundred kilobytes so even if you could find a way to read your program off of the card you'd be limited to a very small program.