I am trying to determine the impact of re-mediating a lucky 13 vulnerability; which i understand requires disabling CBC cipher modes. So far i have added custom logging to my IIS instance to capture and translate the algorithms that clients are connecting with.

Using this i am able to get the cipher, hash, and kex algorithms for each connection. However I was hoping for insight into the MODE (CBC,CTR,GCM). Am i able to derive the mode from the data i am capturing?

# Tag: determining

## Determining equivalence classes of $\{w \in \{0,1\}^*\mid$ the $k$-bit of $w$ from the right is 1$\}$

I want to formally write the equivalence classes of the following language: $ $ L_k = \{w \in \{0,1\}^*\mid\text{ the } k\text{-th bit of }w\text{ from the right is } 1\}$ $

I understand the definition of equivalence classes, yet struggle to come up with a clear intuitive answer.

The language is regular, therefore i’d expect finite equivalence classes.

It seems like the essence of the information I am looking for is only “what is the $ k$ -th bit from the right”, which means i want to focus my attention on suffixes in the form of $ \sigma y \in \{0,1\}^*$ where $ |y|=k-1$ , $ \sigma\in \Sigma$ .

I would highly appreciate some guidance that would build my intuition for finding equivalence classes in general, and in this specific case.

## How is facebook determining my location when I don’t have the app installed?

I have done everything that I can think of to prevent companies like facebook from knowing my actual location, yet recently I’ve started noticing extremely specific ads from them.

For example, I went bowling for the first time in years, and hours later started seeing bowling advertisements on facebook. I believe they only knew this due to my phone being physically present in a bowling alley for an hour.

I initially assumed it was just pareidolia on my part, but it has happened several more times with stores that I have visited.

Things I have done

- Uninstall facebook app
- Disable location services in iOS
- Being very cautious of what I type into search engines
- Avoiding entering store locations into google/apple maps
- Avoid joining public wifi

I’ve checked with my cell phone carrier, and they ‘promise’, that they aren’t selling my location.

What other mechanisms could be leaking my location?

## Determining the maximum value that can be obtained from a loot

**A thief finds much more loot than his bag can fit. We have to find the most valuable combination of items assuming that any fraction of a loot item can be put into his bag.**

For example has a bag which can fit at most 50 Kg of items. He has 3 items to choose from: the first item has a total value of $ 60 for 20 Kg, the second item has a total value of $ 100 for 50 Kg and the last item has a total value of $ 120 for 30 Kg.

So, if the thief takes the most of the item that costs more per unit Kg, he/she can make a better profit out of his/her thievery. In that case, he/she would take 30 Kgs of the third item, and 20 Kgs of the first item, resulting in a total of 50 Kgs (full capacity) with the total value of $ 180.

Here’s my code:

`// THIS IS AN EXAMPLE OF THE FRACTIONAL KNAPSACK PROBLEM #include<cstdio> #include<iostream> #include<vector> using namespace std; double get_max_index(vector<int>, vector<int>); double get_max_value(vector<int>, vector<int>, int); int main() { int num_items, bag_capacity; cout << "Enter the number of items: " << endl; cin >> num_items; cout << "Enter the total capacity that the bag can support: " << endl; cin >> bag_capacity; vector<int> values; vector<int> weights; for (int i = 0; i < num_items; i++) { int buff_val = 0, buff_wgt = 0; cout << "Enter the value and weight of Item " << i + 1 << ": " << endl; cin >> buff_val >> buff_wgt; values.push_back(buff_val); weights.push_back(buff_wgt); } cout.precision(10); cout << "The maximum loot value that can be acquired is " << fixed << get_max_value(values, weights, bag_capacity) << "." << endl; // Always display 'precision' number of digits return 0; } double get_max_index(vector<int> vals, vector<int> wgts){ int max_index = 0; double max_val_per_wgt = 0; for (int i = 0; i < wgts.size(); i++) { if (wgts[i] != 0 && (double) vals[i] / wgts[i] > max_val_per_wgt) { max_val_per_wgt = (double) vals[i] / wgts[i]; max_index = i; } } return max_index; } double get_max_value(vector<int> vals, vector<int> wgts, int capacity){ double max_val = 0.0; for(int i = 0; i < wgts.size(); i++) { if (capacity == 0) { return max_val; // There's no space left in the bag to carry } int max_value_index = get_max_index(vals, wgts); // See which item has the best value per weight index double taken = capacity > wgts[max_value_index] ? wgts[max_value_index] : capacity; // get the minimum of the item's weight and capacity left in the bag max_val += taken * (double) vals[max_value_index] / wgts[max_value_index]; // calculate value for the item's weight taken capacity -= taken; // reduce capacity of the bag by the amount of weight of item taken wgts[max_value_index] -= taken; // reduce the item's weight by the amount taken } return max_val; } `

Please review this code in terms of complexity or in other areas that might result in this code failing. Also, looking forward to criticism and if you decide to post criticism, kindly include relevant details that a not-so-experienced programmer might find helpful in solving the problem.

Thanks in advance! 🙂

## HackerRank Code “Determining DNA Health”

I am working on this problem: https://www.hackerrank.com/challenges/determining-dna-health/problem passing some test cases and time-out on others (no wrong answers).

The code is here:

`import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution { private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int n = scanner.nextInt(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); String[] genesItems = scanner.nextLine().split(" "); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); Map<Integer, String> genes = new HashMap<>(); for (int i = 0; i < n; i++) { genes.put(i, genesItems[i]); } String[] healthItems = scanner.nextLine().split(" "); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); Map<Integer, String> health = new HashMap<>(); for (int i = 0; i < n; i++) { health.put(i, healthItems[i]); } int s = scanner.nextInt(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); long min = Long.MAX_VALUE; long max = Long.MIN_VALUE; for (int sItr = 0; sItr < s; sItr++) { String[] firstLastd = scanner.nextLine().split(" "); int first = Integer.parseInt(firstLastd[0]); int last = Integer.parseInt(firstLastd[1]); String d = firstLastd[2]; long sum = 0; for (int i = first; i <= last; i++) { for (int index = d.indexOf(genes.get(i)); index >= 0; index = d.indexOf(genes.get(i), index + 1)) { sum += Integer.parseInt(health.get(i)); } } if (sum < min) { min = sum; } if (sum > max) { max = sum; } } System.out.println(min + " " + max); scanner.close(); } } `

## HackerRank Code “Determining DNA Health”

I am working on this problem: https://www.hackerrank.com/challenges/determining-dna-health/problem passing some test cases and time-out on others (no wrong answers).

The code is here:

`import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution { private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int n = scanner.nextInt(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); String[] genesItems = scanner.nextLine().split(" "); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); Map<Integer, String> genes = new HashMap<>(); for (int i = 0; i < n; i++) { genes.put(i, genesItems[i]); } String[] healthItems = scanner.nextLine().split(" "); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); Map<Integer, String> health = new HashMap<>(); for (int i = 0; i < n; i++) { health.put(i, healthItems[i]); } int s = scanner.nextInt(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); long min = Long.MAX_VALUE; long max = Long.MIN_VALUE; for (int sItr = 0; sItr < s; sItr++) { String[] firstLastd = scanner.nextLine().split(" "); int first = Integer.parseInt(firstLastd[0]); int last = Integer.parseInt(firstLastd[1]); String d = firstLastd[2]; long sum = 0; for (int i = first; i <= last; i++) { for (int index = d.indexOf(genes.get(i)); index >= 0; index = d.indexOf(genes.get(i), index + 1)) { sum += Integer.parseInt(health.get(i)); } } if (sum < min) { min = sum; } if (sum > max) { max = sum; } } System.out.println(min + " " + max); scanner.close(); } } `

## HackerRank Code “Determining DNA Health”

I am working on this problem: https://www.hackerrank.com/challenges/determining-dna-health/problem passing some test cases and time-out on others (no wrong answers).

The code is here:

`import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution { private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int n = scanner.nextInt(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); String[] genesItems = scanner.nextLine().split(" "); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); Map<Integer, String> genes = new HashMap<>(); for (int i = 0; i < n; i++) { genes.put(i, genesItems[i]); } String[] healthItems = scanner.nextLine().split(" "); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); Map<Integer, String> health = new HashMap<>(); for (int i = 0; i < n; i++) { health.put(i, healthItems[i]); } int s = scanner.nextInt(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); long min = Long.MAX_VALUE; long max = Long.MIN_VALUE; for (int sItr = 0; sItr < s; sItr++) { String[] firstLastd = scanner.nextLine().split(" "); int first = Integer.parseInt(firstLastd[0]); int last = Integer.parseInt(firstLastd[1]); String d = firstLastd[2]; long sum = 0; for (int i = first; i <= last; i++) { for (int index = d.indexOf(genes.get(i)); index >= 0; index = d.indexOf(genes.get(i), index + 1)) { sum += Integer.parseInt(health.get(i)); } } if (sum < min) { min = sum; } if (sum > max) { max = sum; } } System.out.println(min + " " + max); scanner.close(); } } `

## HackerRank Code “Determining DNA Health”

The code is here:

`import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution { private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int n = scanner.nextInt(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); String[] genesItems = scanner.nextLine().split(" "); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); Map<Integer, String> genes = new HashMap<>(); for (int i = 0; i < n; i++) { genes.put(i, genesItems[i]); } String[] healthItems = scanner.nextLine().split(" "); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); Map<Integer, String> health = new HashMap<>(); for (int i = 0; i < n; i++) { health.put(i, healthItems[i]); } int s = scanner.nextInt(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); long min = Long.MAX_VALUE; long max = Long.MIN_VALUE; for (int sItr = 0; sItr < s; sItr++) { String[] firstLastd = scanner.nextLine().split(" "); int first = Integer.parseInt(firstLastd[0]); int last = Integer.parseInt(firstLastd[1]); String d = firstLastd[2]; long sum = 0; for (int i = first; i <= last; i++) { for (int index = d.indexOf(genes.get(i)); index >= 0; index = d.indexOf(genes.get(i), index + 1)) { sum += Integer.parseInt(health.get(i)); } } if (sum < min) { min = sum; } if (sum > max) { max = sum; } } System.out.println(min + " " + max); scanner.close(); } } `

## SAT algorithm for determining if a graph is disjoint

What are some good algorithms to have a SAT (CNF) solver determine if a given graph is fully-connected or disjoint?

The best one I can think of is this:

- Number the nodes 1..N, where N is the number of nodes in the graph.
- define N^3 variables with the ordered pair (P, Q), where P = 1..N and Q = 0..N^2-1.
- Set (1,0) to true.
- Set (A,P+1) to true iff there is an edge connecting node A and node B and (B,P) is true.
- If there exists a true (X,Y) variable for all possible nodes X, then the graph is connected.

Effectively, (X,Y) means “Node X is Y steps away from node X”.

This seems inefficient at O(N^3) variables. Can this be improved?

A comment (from when I posted this on cstheory.stackexchange.com) asked why I would need a SAT-based algorithm when O(N) algorithms for connectivity are well-known. The reason is simple — I have many other SAT-based constraints on the graph that also need to be satisfied at the same time.

## Does this house rule, for determining hit point maximum, make characters weaker than RAW?

Recently my friend had mentioned that he was using a house rule for his players to calculate their hit point maximum, which I am both curious & hesitant to try with my players.

His way of determining hit points is **(Str mod + Con mod + 4) per level, with a minimum of 1 per level**. Apparently the minimum had to be added when a player purposely made a sickly character. Also, he said that the class isn’t considered as those with larger Hit Dice are assumed to have more Strength.

From what I can see this makes characters too weak compared to RAW. Is my assessment correct?